forked from ansible-collections/community.aws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aws2_ec2 inventory: populate ec2_tag_* hostvars (ansible-collections#331
) aws2_ec2 inventory: populate ec2_tag_* hostvars Reviewed-by: https://github.com/apps/ansible-zuul
- Loading branch information
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/fragments/331_aws_ec2_inventory_use_contrib_script_compatible_ec2_tag_keys.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...ts/inventory_aws_ec2/playbooks/test_populating_inventory_with_use_contrib_script_keys.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
- hosts: 127.0.0.1 | ||
connection: local | ||
gather_facts: no | ||
environment: "{{ ansible_test.environment }}" | ||
tasks: | ||
|
||
- module_defaults: | ||
group/aws: | ||
aws_access_key: '{{ aws_access_key }}' | ||
aws_secret_key: '{{ aws_secret_key }}' | ||
security_token: '{{ security_token | default(omit) }}' | ||
region: '{{ aws_region }}' | ||
block: | ||
|
||
# Create VPC, subnet, security group, and find image_id to create instance | ||
- include_tasks: setup.yml | ||
|
||
# Create new host, refresh inventory | ||
- name: create a new host | ||
ec2: | ||
image: '{{ image_id }}' | ||
exact_count: 1 | ||
count_tag: | ||
Name: '{{ resource_prefix }}:/aa' | ||
instance_tags: | ||
Name: '{{ resource_prefix }}:/aa' | ||
OtherTag: value | ||
instance_type: t2.micro | ||
wait: yes | ||
group_id: '{{ sg_id }}' | ||
vpc_subnet_id: '{{ subnet_id }}' | ||
register: setup_instance | ||
|
||
- meta: refresh_inventory | ||
|
||
- name: "register the current hostname, the : and / a replaced with _" | ||
set_fact: | ||
expected_hostname: "{{ resource_prefix }}__aa" | ||
|
||
- name: "Ensure we've got a hostvars entry for the new host" | ||
assert: | ||
that: | ||
- expected_hostname in hostvars | ||
- hostvars[expected_hostname].ec2_tag_OtherTag == "value" | ||
|
||
always: | ||
|
||
- name: remove setup ec2 instance | ||
ec2: | ||
instance_type: t2.micro | ||
instance_ids: '{{ setup_instance.instance_ids }}' | ||
state: absent | ||
wait: yes | ||
instance_tags: | ||
Name: '{{ resource_prefix }}' | ||
group_id: "{{ sg_id }}" | ||
vpc_subnet_id: "{{ subnet_id }}" | ||
ignore_errors: yes | ||
when: setup_instance is defined | ||
|
||
- include_tasks: tear_down.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...gration/targets/inventory_aws_ec2/templates/inventory_with_use_contrib_script_keys.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
plugin: amazon.aws.aws_ec2 | ||
aws_access_key_id: '{{ aws_access_key }}' | ||
aws_secret_access_key: '{{ aws_secret_key }}' | ||
{% if security_token | default(false) %} | ||
aws_security_token: '{{ security_token }}' | ||
{% endif %} | ||
regions: | ||
- '{{ aws_region }}' | ||
filters: | ||
tag:Name: | ||
- '{{ resource_prefix }}:/aa' | ||
hostnames: | ||
- tag:Name | ||
use_contrib_script_compatible_sanitization: True | ||
use_contrib_script_compatible_ec2_tag_keys: True |