-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathaws.yaml
63 lines (59 loc) · 1.78 KB
/
aws.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
---
-
hosts: localhost
name: "Create Windows Server"
tasks:
- set_fact:
yeppers: "ansible-windows-{{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=8') }}"
-
amazon.aws.ec2_instance:
aws_access_key: KEY
aws_secret_key: KEY
image_id: ami-03aeb14d816dc98ed
instance_type: t2.medium
key_name: NetworkChuck-Admin
name: "{{ yeppers }}"
network:
assign_public_ip: true
region: us-east-1
security_group:
vpc_subnet_id:
name: "start an instance with a public IP address"
-
ansible.builtin.pause:
minutes: 1
name: "Pause for 1 minute to allow for instance creation"
-
amazon.aws.ec2_instance_info:
aws_access_key:
aws_secret_key:
filters:
instance-state-name:
- running
? "tag:Name"
: "{{ yeppers }}"
region: us-east-1
name: "Grab instance info"
register: instance_info
- name: Set ip variable
set_fact:
pub_ip: "{{ instance_info | community.general.json_query('instances[].network_interfaces[].association.public_ip[] | [0]') }}"
- name: print variable
ansible.builtin.debug:
var: pub_ip
- name: Slack Notification
community.general.slack:
token:
msg: |
### Your AWS Server is READY!! ###
--------------------------------------
``
`Server`: "{{ yeppers }}"
`IP ADDRESS`: "{{ pub_ip }}"
--------------------------------------
channel: '#ansible'
color: good
username: 'Ansible on {{ inventory_hostname }}'
link_names: 0
parse: 'none'
ignore_errors: true