-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alina Buzachis <[email protected]>
- Loading branch information
1 parent
d915b86
commit 0ff5348
Showing
5 changed files
with
117 additions
and
82 deletions.
There are no files selected for viewing
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
59 changes: 59 additions & 0 deletions
59
...egration/targets/inventory_aws_ec2/playbooks/test_populating_inventory_with_hostnames.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,59 @@ | ||
--- | ||
- hosts: 127.0.0.1 | ||
connection: local | ||
gather_facts: false | ||
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 | ||
- name: create a new host | ||
ec2_instance: | ||
image_id: '{{ image_id }}' | ||
name: '{{ resource_prefix }}' | ||
tags: | ||
Tag1: Test1 | ||
Tag2: Test2 | ||
instance_type: t2.micro | ||
security_groups: '{{ sg_id }}' | ||
vpc_subnet_id: '{{ subnet_id }}' | ||
wait: false | ||
register: setup_instance | ||
|
||
# refresh inventory | ||
- meta: refresh_inventory | ||
|
||
- name: assert groups and hostvars were populated with inventory | ||
assert: | ||
that: | ||
- "'aws_ec2' in groups" | ||
- groups['aws_ec2'] | length == 2 | ||
- "'Test1' in groups['aws_ec2']" | ||
- "'Test2' in groups['aws_ec2']" | ||
- "'Test1' in hostvars" | ||
- "'Test2' in hostvars" | ||
|
||
always: | ||
|
||
- name: remove 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: true | ||
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
21 changes: 21 additions & 0 deletions
21
tests/integration/targets/inventory_aws_ec2/templates/inventory_with_hostnames.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,21 @@ | ||
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 }}' | ||
keyed_groups: | ||
- prefix: tag | ||
key: tags | ||
hostnames: | ||
# can also be specified using | ||
# - tag:Tag1,Tag2 | ||
# or | ||
# - tag:Tag1=Test1,Tag2=Test2 | ||
# or | ||
- tag:Tag1 | ||
- tag:Tag2 | ||
compose: | ||
ansible_host: private_ip_address |
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