-
Notifications
You must be signed in to change notification settings - Fork 2
/
aws.show.yaml
372 lines (307 loc) · 6.98 KB
/
aws.show.yaml
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
---
#------------------------------------------------------------------------------
# Show AWS Info
#
# Export your AWS Access & Secret keys into your terminal environment for
# authentication of the calls below:
#
# export AWS_REGION='us-west-1'
# export AWS_ACCESS_KEY='AKIAIOSF/EXAMPLE+KEY'
# export AWS_SECRET_KEY='wJalrXUtnFEMI/K7MDENG/bPxRfi/EXAMPLE+KEY'
#
# Invoke with tag names to only get what you need:
#
# ansible-playbook aws.show.yaml --tags vpc,sg
#------------------------------------------------------------------------------
- name: Show AWS Info Playbook
gather_facts: no
hosts: localhost
vars_files:
- vars/main.yaml
tasks:
#
# Show Caller Info - the user and account being used to make AWS calls
#
- name: Get the current caller identity information
amazon.aws.aws_caller_info:
register: caller_info
tags:
- caller
- name: caller_info
ansible.builtin.debug: var=caller_info
tags:
- caller
#
# Show Regions
#
- name: Info for All Regions
community.aws.aws_region_info:
# filters:
register: result
tags:
- region
- regions
- name: List of Region Names
when: result is defined and result != []
loop: "{{ result.regions }}"
vars:
region_names: []
ansible.builtin.set_fact:
region_names: "{{ region_names + [ item.region_name ] }}"
tags:
- region
- regions
- name: Region Names
ansible.builtin.debug: var=region_names
tags:
- region
- regions
#
# Show Availability Zones
#
- name: Get All Availability Zones in a Region
amazon.aws.aws_az_info:
register: azs
tags:
- az
- availability_zone
- name: List of Availability Zone Names
when: azs is defined and azs != []
loop: "{{ azs.availability_zones }}"
vars:
az_names: []
ansible.builtin.set_fact:
az_names: "{{ az_names + [ item.zone_name ] }}"
tags:
- az
- availability_zone
- name: Availability Zone Names
ansible.builtin.debug: var=az_names
tags:
- az
- availability_zone
#
# Show VPCs
#
- name: Get VPC(s)
amazon.aws.ec2_vpc_net_info:
# name: "{{ aws_vpc_name }}"
# cidr_block: "{{ aws_vpc_cidr }}"
# region: "{{ aws_region }}"
register: vpcs
tags:
- vpc
- vpcs
- name: Show vpcs
ansible.builtin.debug: var=vpcs
tags:
- vpc
- vpcs
#
# EC2 Instances
#
- name: Query AWS EC2 Instances
community.aws.ec2_instance_info:
region: "{{ aws_region }}"
filters:
"tag:project": "{{ project_name }}"
instance-state-name: running
register: instances
tags:
- ec2
- instances
- name: Show instances
ansible.builtin.debug: var=instances
tags:
- ec2
- instances
- name: List of AWS EC2 Instances
when: instances is defined and instances != []
loop: "{{ instances.instances }}"
vars:
instance_names: []
attrs: ['image_id', 'instance_id', 'instance_type', 'key_name', 'private_ip_address', 'public_ip_address' ]
ansible.builtin.set_fact:
instance_names: "{{ instance_names + [ item.tags.Name ] }}"
tags:
- ec2
- instances
- name: Show AWS EC2 Instances by Name
ansible.builtin.debug: var=instance_names
tags:
- ec2
- instances
#
# Show Security Groups
#
- name: Show Security Groups
amazon.aws.ec2_group_info:
# filters:
# vpc_id: "{{ vpcs.vpcs.id }}"
# region: "{{ aws_region }}"
register: security_groups
tags:
- sg
- security_group
- name: Show security_groups
ansible.builtin.debug: var=security_groups
tags:
- sg
- security_group
- name: Get All Security Groups
amazon.aws.ec2_group_info:
register: sgs
tags:
- sg
- security_group
- name: List of Security Groups
when: sgs is defined and sgs != []
loop: "{{ sgs.security_groups }}"
vars:
sg_names: []
ansible.builtin.set_fact:
sg_names: "{{ sg_names + [ item.group_id + ' | ' + item.group_name ] }}"
tags:
- sg
- security_group
- name: sg_names
ansible.builtin.debug: var=sg_names
tags:
- sg
- security_group
- name: Get details for Security Groups
amazon.aws.ec2_group_info:
filters:
group-name: "{{ sg_names }}"
register: sg_details
tags:
- sg
- security_group
- name: sg_details
ansible.builtin.debug: var=sg_details
tags:
- sg
- security_group
#
# Show CloudFormation stack(s)
#
- name: Get All CloudFormation info
amazon.aws.cloudformation_info:
register: stacks
tags:
- cf
- cft
- cloudformation
- stacks
- name: stacks.cloudformation
ansible.builtin.debug: var=stacks.cloudformation
tags:
- cf
- cft
- cloudformation
- stacks
- name: List of CloudFormation Stacks
when: stacks is defined and stacks != []
loop: "{{ lookup('dict', stacks.cloudformation) }}"
vars:
stack_names: []
ansible.builtin.set_fact:
stack_names: "{{ stack_names + [ item.key ] }}"
tags:
- cf
- cft
- cloudformation
- stacks
- name: stack_names
ansible.builtin.debug: var=stack_names
tags:
- cf
- cft
- cloudformation
- stacks
#
# Show ec2 ENI interfaces in AWS
#
- name: Get All ec2_eni_info
amazon.aws.ec2_group_info:
# filters:
# network-interface-id: eni-xxxxxxx
register: result
tags:
- eni
- name: List of ENI
when: result is defined and result != []
loop: "{{ result.security_groups }}"
vars:
eni_names: []
ansible.builtin.set_fact:
eni_names: "{{ eni_names + [ item.group_id + ' | ' + item.group_name ] }}"
tags:
- eni
- name: eni_names
ansible.builtin.debug: var=eni_names
tags:
- eni
#
# Show ec2 volumes in AWS
#
- name: Get All Volumes
amazon.aws.ec2_vol_info:
region: "{{ aws_region }}"
register: result
tags:
- volume
- volumes
- name: result
ansible.builtin.debug: var=result
tags:
- volume
- volumes
#
# Show dhcp options sets in AWS
#
- name: Get All ec2_vpc_dhcp_option_info
amazon.aws.ec2_vpc_dhcp_option_info:
region: "{{ aws_region }}"
register: result
tags:
- vpc
- dhcp
- name: result
ansible.builtin.debug: var=result
tags:
- vpc
- dhcp
#
# ec2_vpc_net_info – Gather information about ec2 VPCs in AWS
#
- name: Get All ec2_vpc_net_info
amazon.aws.ec2_vpc_net_info:
region: "{{ aws_region }}"
register: result
tags:
- vpc
- net
- network
- name: result
ansible.builtin.debug: var=result
tags:
- vpc
- net
- network
#
# Show ec2 VPC subnets in AWS
#
- name: Get All ec2_vpc_subnet_info
amazon.aws.ec2_vpc_subnet_info:
region: "{{ aws_region }}"
register: result
tags:
- subnet
- vpc
- name: result
ansible.builtin.debug: var=result
tags:
- subnet
- vpc
...