Skip to content

Commit

Permalink
aws2_ec2 inventory: populate ec2_tag_* hostvars
Browse files Browse the repository at this point in the history
This patch exposes a new `use_contrib_script_compatible_ec2_tag_keys`
that can be used to reproduce a behior of the old `ec2.py` inventory
script from contrib.

Closes: ansible-collections#183
  • Loading branch information
goneri committed Apr 16, 2021
1 parent 8011d3a commit a13e788
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- "aws_ec2 inventory - expose a new configuration key ``use_contrib_script_compatible_ec2_tag_keys`` to reproduce a behavior of the old ``ec2.py`` inventory script. With this option enabled, each tag is exposed using a ``ec2_tag_TAGNAME`` key (https://github.com/ansible-collections/amazon.aws/pull/331)."
10 changes: 10 additions & 0 deletions plugins/inventory/aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
which group names end up being used as.
type: bool
default: False
use_contrib_script_compatible_ec2_tag_keys:
description:
- Expose the host tags with ec2_tag_TAGNAME keys like the old ec2.py inventory script.
- The use of this feature is discouraged and we advise to migrate to the new ``tags`` structure.
type: bool
default: False
'''

EXAMPLES = '''
Expand Down Expand Up @@ -564,6 +570,10 @@ def _add_hosts(self, hosts, group, hostnames):
host = camel_dict_to_snake_dict(host, ignore_list=['Tags'])
host['tags'] = boto3_tag_list_to_ansible_dict(host.get('tags', []))

if self.get_option('use_contrib_script_compatible_ec2_tag_keys'):
for k, v in host['tags'].items():
host["ec2_tag_%s" % k] = v

# Allow easier grouping by region
host['placement']['region'] = host['placement']['availability_zone'][:-1]

Expand Down

0 comments on commit a13e788

Please sign in to comment.