[PR #9449/0bbc3ecc backport][stable-10] manageiq_alert_profiles: improve handling param requirements (#9464)

manageiq_alert_profiles: improve handling param requirements (#9449)

* manageiq_alert_profiles: improve handling param requirements

Basically two changes:
* `name` is already required when state is either present or absent, and there are no other states, so making it fully required and removing the conditional
* `alerts` is documented as required when state=present, this has been verified in the code, so added that parameter to the existing `required_if` spec.

* add changelog frag

(cherry picked from commit 0bbc3eccd9)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
pull/9469/head
patchback[bot] 2024-12-29 21:24:30 +01:00 committed by GitHub
parent 6f774fd4a5
commit 6b02eaa795
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 8 deletions

View File

@ -0,0 +1,2 @@
minor_changes:
- manageiq_alert_profiles - improve handling of parameter requirements (https://github.com/ansible-collections/community.general/pull/9449).

View File

@ -37,7 +37,7 @@ options:
type: str
description:
- The unique alert profile name in ManageIQ.
- Required when state is "absent" or "present".
required: true
resource_type:
type: str
description:
@ -114,8 +114,7 @@ class ManageIQAlertProfiles(object):
"""
alerts = []
for alert_description in alert_descriptions:
alert = self.manageiq.find_collection_resource_or_fail("alert_definitions",
description=alert_description)
alert = self.manageiq.find_collection_resource_or_fail("alert_definitions", description=alert_description)
alerts.append(alert['href'])
return alerts
@ -253,7 +252,7 @@ class ManageIQAlertProfiles(object):
def main():
argument_spec = dict(
name=dict(type='str'),
name=dict(type='str', required=True),
resource_type=dict(type='str', choices=['Vm',
'ContainerNode',
'MiqServer',
@ -270,8 +269,7 @@ def main():
argument_spec.update(manageiq_argument_spec())
module = AnsibleModule(argument_spec=argument_spec,
required_if=[('state', 'present', ['name', 'resource_type']),
('state', 'absent', ['name'])])
required_if=[('state', 'present', ['resource_type', 'alerts'])])
state = module.params['state']
name = module.params['name']
@ -279,8 +277,7 @@ def main():
manageiq = ManageIQ(module)
manageiq_alert_profiles = ManageIQAlertProfiles(manageiq)
existing_profile = manageiq.find_collection_resource_by("alert_definition_profiles",
name=name)
existing_profile = manageiq.find_collection_resource_by("alert_definition_profiles", name=name)
# we need to add or update the alert profile
if state == "present":