mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[ec2-ami] Use required_if with state parameter (#32009)
* [ec2-ami] Use required_if with state parameter * Update failure msg on delete ami with no image_id task in integration test
This commit is contained in:
parent
6203e899f0
commit
8a9a9b84dd
2 changed files with 6 additions and 7 deletions
|
@ -616,7 +616,11 @@ def main():
|
||||||
launch_permissions=dict(type='dict')
|
launch_permissions=dict(type='dict')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
module = AnsibleModule(argument_spec=argument_spec)
|
module = AnsibleModule(
|
||||||
|
argument_spec=argument_spec,
|
||||||
|
required_if=[('state', 'present', ('name',)),
|
||||||
|
('state', 'absent', ('image_id',))]
|
||||||
|
)
|
||||||
|
|
||||||
if not HAS_BOTO:
|
if not HAS_BOTO:
|
||||||
module.fail_json(msg='boto required for this module')
|
module.fail_json(msg='boto required for this module')
|
||||||
|
@ -627,9 +631,6 @@ def main():
|
||||||
module.fail_json(msg="Error while connecting to aws: %s" % str(e))
|
module.fail_json(msg="Error while connecting to aws: %s" % str(e))
|
||||||
|
|
||||||
if module.params.get('state') == 'absent':
|
if module.params.get('state') == 'absent':
|
||||||
if not module.params.get('image_id'):
|
|
||||||
module.fail_json(msg='image_id needs to be an ami image to registered/delete')
|
|
||||||
|
|
||||||
deregister_image(module, ec2)
|
deregister_image(module, ec2)
|
||||||
|
|
||||||
elif module.params.get('state') == 'present':
|
elif module.params.get('state') == 'present':
|
||||||
|
@ -640,8 +641,6 @@ def main():
|
||||||
# Changed is always set to true when provisioning new AMI
|
# Changed is always set to true when provisioning new AMI
|
||||||
if not module.params.get('instance_id') and not module.params.get('device_mapping'):
|
if not module.params.get('instance_id') and not module.params.get('device_mapping'):
|
||||||
module.fail_json(msg='instance_id or device_mapping (register from ebs snapshot) parameter is required for new image')
|
module.fail_json(msg='instance_id or device_mapping (register from ebs snapshot) parameter is required for new image')
|
||||||
if not module.params.get('name'):
|
|
||||||
module.fail_json(msg='name parameter is required for new image')
|
|
||||||
create_image(module, ec2)
|
create_image(module, ec2)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "result.failed"
|
- "result.failed"
|
||||||
- "result.msg == 'image_id needs to be an ami image to registered/delete'"
|
- "result.msg == 'state is absent but the following are missing: image_id'"
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue