-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathin_memory_inventory.yml
64 lines (43 loc) · 1.4 KB
/
in_memory_inventory.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
- hosts: localhost
gather_facts: false
tasks:
- name: Gather Facts from aws
#ec2_instance_info:
ec2_instance_facts:
region: us-east-1
filters:
"tag:owner": [email protected]
register: ec2_instances
- name: Print registered variable ec2_instances
debug:
var: ec2_instances
# - pause:
- name: Print filtered output
debug:
msg: "{{ item.0 }} and {{ item.1 }} and {{ item.2}}"
with_together:
- "{{ ec2_instances.instances | map(attribute='tags.AnsibleGroup')| list }}"
- "{{ ec2_instances.instances | map(attribute='public_ip_address')| list }}"
- "{{ ec2_instances.instances | map(attribute='tags.Name')| list }}"
# - pause:
- name: Create In Memory Inventory
add_host:
group: "{{item.0}}"
hostname: "{{item.2}}"
ansible_host: "{{item.1}}"
ansible_ssh_private_key_file: ~/.ssh/cloud-user.pem
ansible_ssh_user: cloud-user
with_together:
- "{{ ec2_instances.instances | map(attribute='tags.AnsibleGroup')| list }}"
- "{{ ec2_instances.instances | map(attribute='public_ip_address')| list }}"
- "{{ ec2_instances.instances | map(attribute='tags.Name')| list }}"
- debug: var=groups
# - pause:
- name: Test play against In-memory inventory
hosts: bastion
gather_facts: false
tasks:
- ping:
register: ping_output
- debug: var=ping_output