forked from ansible-collections/amazon.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.
inventory aws_ec2 - allow for literal strings in hostnames (ansible-c…
…ollections#826) inventory aws_ec2 - allow for literal strings in hostnames SUMMARY Allow for literal strings in hostnames rather than throwing an AnsibleError Fixes ansible-collections#814 ISSUE TYPE Feature Pull Request COMPONENT NAME aws_ec2 ADDITIONAL INFORMATION Is there a better way of allowing for literal strings here? Reviewed-by: Markus Bergholz <[email protected]> Reviewed-by: Alina Buzachis <None> Reviewed-by: Joseph Torcasso <None> Reviewed-by: Jill R <None>
- Loading branch information
1 parent
23a8ac9
commit 944bb1f
Showing
5 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
changelogs/fragments/826-inventory-aws_ec2-allow-literal-string-in-hostname.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,2 @@ | ||
minor_changes: | ||
- aws_ec2 inventory - Allow for literal strings in hostname that don't match filter parameters in ec2 describe-instances (https://github.com/ansible-collections/amazon.aws/pull/826). |
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
56 changes: 56 additions & 0 deletions
56
...ion/targets/inventory_aws_ec2/playbooks/test_populating_inventory_with_literal_string.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,56 @@ | ||
--- | ||
- 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_instance: | ||
image_id: '{{ image_id }}' | ||
name: '{{ resource_prefix }}' | ||
tags: | ||
OtherTag: value | ||
instance_type: t2.micro | ||
security_groups: '{{ sg_id }}' | ||
vpc_subnet_id: '{{ subnet_id }}' | ||
wait: no | ||
register: setup_instance | ||
|
||
- meta: refresh_inventory | ||
|
||
- name: register the current hostname | ||
set_fact: | ||
expected_hostname: "aws-{{ resource_prefix }}" | ||
|
||
- name: "Ensure we've got a hostvars entry for the new host" | ||
assert: | ||
that: | ||
- expected_hostname in hostvars | ||
|
||
always: | ||
|
||
- name: remove setup ec2 instance | ||
ec2_instance: | ||
instance_type: t2.micro | ||
instance_ids: '{{ setup_instance.instance_ids }}' | ||
state: absent | ||
name: '{{ resource_prefix }}' | ||
security_groups: "{{ 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
tests/integration/targets/inventory_aws_ec2/templates/inventory_with_literal_string.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 }}' | ||
hostnames: | ||
- name: 'tag:Name' | ||
separator: '-' | ||
prefix: 'aws' |