From 1462fd740b279ebe7dd791c8cac338a36ad413f6 Mon Sep 17 00:00:00 2001 From: "James E. King III" Date: Wed, 8 May 2019 05:07:19 -0400 Subject: [PATCH] ec2_instance fix name idempotency (#55224) --- .../fragments/55224-ec2_instance-idempotent-tags.yaml | 2 ++ lib/ansible/modules/cloud/amazon/ec2_instance.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/55224-ec2_instance-idempotent-tags.yaml diff --git a/changelogs/fragments/55224-ec2_instance-idempotent-tags.yaml b/changelogs/fragments/55224-ec2_instance-idempotent-tags.yaml new file mode 100644 index 00000000000..468dc44eed6 --- /dev/null +++ b/changelogs/fragments/55224-ec2_instance-idempotent-tags.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ec2_instance - make Name tag idempotent (https://github.com/ansible/ansible/pull/55224) diff --git a/lib/ansible/modules/cloud/amazon/ec2_instance.py b/lib/ansible/modules/cloud/amazon/ec2_instance.py index 011d1cce18e..c186cbbccee 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_instance.py +++ b/lib/ansible/modules/cloud/amazon/ec2_instance.py @@ -1680,7 +1680,11 @@ def main(): for match in existing_matches: warn_if_public_ip_assignment_changed(match) warn_if_cpu_options_changed(match) - changed |= manage_tags(match, (module.params.get('tags') or {}), module.params.get('purge_tags', False), ec2) + tags = module.params.get('tags') or {} + name = module.params.get('name') + if name: + tags['Name'] = name + changed |= manage_tags(match, tags, module.params.get('purge_tags', False), ec2) if state in ('present', 'running', 'started'): ensure_present(existing_matches=existing_matches, changed=changed, ec2=ec2, state=state)