mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.2 KiB
YAML
75 lines
2.2 KiB
YAML
5 years ago
|
- name: test updating inventory
|
||
|
block:
|
||
|
- name: assert group was populated with inventory but is empty
|
||
|
assert:
|
||
|
that:
|
||
|
- "'aws_ec2' in groups"
|
||
|
- "not groups.aws_ec2"
|
||
|
|
||
|
- name: set connection information for all tasks
|
||
|
set_fact:
|
||
|
aws_connection_info: &aws_connection_info
|
||
|
aws_access_key: "{{ aws_access_key }}"
|
||
|
aws_secret_key: "{{ aws_secret_key }}"
|
||
|
security_token: "{{ security_token }}"
|
||
|
region: "{{ aws_region }}"
|
||
|
no_log: yes
|
||
|
|
||
|
- name: create a new host
|
||
|
ec2:
|
||
|
image: "{{ images[aws_region] }}"
|
||
|
exact_count: 1
|
||
|
count_tag:
|
||
|
Name: '{{ resource_prefix }}'
|
||
|
instance_tags:
|
||
|
Name: '{{ resource_prefix }}'
|
||
|
instance_type: t2.micro
|
||
|
wait: yes
|
||
|
group_id: '{{ setup_sg.group_id }}'
|
||
|
vpc_subnet_id: '{{ setup_subnet.subnet.id }}'
|
||
|
<<: *aws_connection_info
|
||
|
register: setup_instance
|
||
|
|
||
|
- meta: refresh_inventory
|
||
|
|
||
|
- name: assert group was populated with inventory and is no longer empty
|
||
|
assert:
|
||
|
that:
|
||
|
- "'aws_ec2' in groups"
|
||
|
- "groups.aws_ec2 | length == 1"
|
||
|
- "groups.aws_ec2.0 == '{{ resource_prefix }}'"
|
||
|
|
||
|
- 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: '{{ setup_sg.group_id }}'
|
||
|
vpc_subnet_id: '{{ setup_subnet.subnet.id }}'
|
||
|
<<: *aws_connection_info
|
||
|
|
||
|
- meta: refresh_inventory
|
||
|
|
||
|
- name: assert group was populated with inventory but is empty
|
||
|
assert:
|
||
|
that:
|
||
|
- "'aws_ec2' in groups"
|
||
|
- "not groups.aws_ec2"
|
||
|
|
||
|
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: '{{ setup_sg.group_id }}'
|
||
|
vpc_subnet_id: '{{ setup_subnet.subnet.id }}'
|
||
|
<<: *aws_connection_info
|
||
|
ignore_errors: yes
|