Skip to content

Commit

Permalink
Add more integrations
Browse files Browse the repository at this point in the history
Signed-off-by: Alina Buzachis <[email protected]>
  • Loading branch information
alinabuzachis committed Jun 22, 2022
1 parent b04f4e0 commit af9d0fe
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
# refresh inventory
- meta: refresh_inventory

- debug:
var: groups

- name: assert groups and hostvars were populated with inventory
assert:
that:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
- 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

- debug:
var: groups

- name: assert groups and hostvars were populated with inventory
assert:
that:
- "'aws_ec2' in groups"
- groups['aws_ec2'] | length == 2
- "'Tag1_Test1' in groups['aws_ec2']"
- "'Tag2_Test2' in groups['aws_ec2']"
- "'Tag1_Test1' in hostvars"
- "'Tag2_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
6 changes: 4 additions & 2 deletions tests/integration/targets/inventory_aws_ec2/runme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ ansible-playbook playbooks/create_inventory_config.yml -e "template='inventory_w
ansible-playbook playbooks/test_populating_inventory_with_concatenation.yml "$@"
ansible-playbook playbooks/create_inventory_config.yml -e "template='inventory_with_literal_string.yml.j2'" "$@"
ansible-playbook playbooks/test_populating_inventory_with_literal_string.yml "$@"
ansible-playbook playbooks/create_inventory_config.yml -e "template='inventory_with_hostnames.yml.j2'" "$@"
ansible-playbook playbooks/test_populating_inventory_with_hostnames.yml "$@"
ansible-playbook playbooks/create_inventory_config.yml -e "template='inventory_with_hostnames_using_tags_classic.yml.j2'" "$@"
ansible-playbook playbooks/test_populating_inventory_with_hostnames_using_tags_classic.yml "$@"
ansible-playbook playbooks/create_inventory_config.yml -e "template='inventory_with_hostnames_using_tags.yml.j2'" "$@"
ansible-playbook playbooks/test_populating_inventory_with_hostnames_using_tags.yml "$@"

# generate inventory config with includes_entries_matching and prepare the tests
ansible-playbook playbooks/create_inventory_config.yml -e "template='inventory_with_include_or_exclude_filters.yml.j2'" "$@"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ hostnames:
# can also be specified using
# - tag:Tag1,Tag2
# or
# - tag:Tag1=Test1,Tag2=Test2
# or
- tag:Tag1
- tag:Tag2
#- tag:Tag1=Test1,Tag2=Test2
compose:
ansible_host: private_ip_address
ansible_host: private_ip_address
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

0 comments on commit af9d0fe

Please sign in to comment.