-
Notifications
You must be signed in to change notification settings - Fork 12
/
playbook.yaml
64 lines (57 loc) · 1.87 KB
/
playbook.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
---
- hosts: localhost
vars:
- ansible_ec2_instance_id: i-03f7d9f815835e98a
- ansible_ec2_placement_region: ap-south-1
tasks:
- name: Gather EC2 instance metadata
action: ec2_metadata_facts
- name: Gather EC2 instance metadata
#action: ec2_instance_facts
ec2_remote_facts:
region: "{{ ansible_ec2_placement_region }}"
register: ec2_facts
- name: Obtain EC2 tags for this instance
local_action:
module: ec2_tag
region: "{{ ansible_ec2_placement_region }}"
resource: "{{ item }}"
state: list
register: ec2_tags
with_items: "{{ ec2_facts.instances|selectattr('state', 'equalto', 'running')|map(attribute='id')|list }}"
- block:
- name: Remove Temporary files
file:
path: "{{ item }}"
state: absent
with_items:
- instanceid
- tags
ignore_errors: yes
- name: "Creating Instance ID's file"
shell: echo "Instance ID {{ item }}" >>./instanceid
with_items:
- "{{ ec2_tags.results |map(attribute='item')|list}}"
- name: "Creating Tag Result file"
shell: echo "Tag Value {{ item }}" >>./tags
with_items:
- "{{ ec2_tags.results |map(attribute='tags')|list}}"
#when: ( "{{ item }}" == "{}")
- name: "Join Result Files"
shell: paste ./instanceid ./tags | grep '{}'> final
register: cmdln
failed_when: "cmdln.rc == 2"
check_mode: no
- name: Sending Email
mail:
host: 127.0.0.1
port: 25
subject: Ansible-report
body: Hello, this is an e-mail. I hope you like it ;-)
from: [email protected] (Ansible Playbook)
to: Anuj Sharma <[email protected]>, Vinay Raj <[email protected]>
cc: Server Root <root@localhost>
attach: ./playbook.yaml ../final
headers: '[email protected]|X-Special="Something or other"'
charset: utf8
delegate_to: localhost