forked from wzzrd/automates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_ec2_instances.yml
72 lines (63 loc) · 2.11 KB
/
create_ec2_instances.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
- name: create instance(s) on ec2
hosts: localhost
gather_facts: no
tasks:
- name: create instance(s) on ec2
ec2:
image: ami-0badcc5b522737046
instance_type: t2.medium
key_name: ansible_tower
assign_public_ip: yes
wait: yes
exact_count: "{{ count }}"
region: eu-central-1
wait_timeout: 300
count_tag:
event: "{{ tag }}"
instance_tags:
event: "{{ tag }}"
vpc_subnet_id: subnet-900e39da
group_id: sg-b2d436da
register: ec2
delegate_to: localhost
- name: add new hosts to tmpgroup
add_host:
name: "{{ item.public_dns_name }}"
groups: tmpgroup
loop: "{{ ec2.instances }}"
- name: show me the ec2 variable
debug:
var: ec2
verbosity: 2
- name: check connectivity and set-up user
hosts: tmpgroup
remote_user: ec2-user
become: yes
gather_facts: no
tasks:
- name: wait for instances to come up
wait_for_connection:
delay: 10
- name: create ansible user
user:
name: ansible
groups: wheel
append: yes
uid: 1010
state: present
- name: inject ssh key
authorized_key:
user: ansible
key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCy1QtNy21ILU3OjY0vgGCFYB5EWZLOwCMe4GqTjFfeVDvBgbQzHmf9OHMcoTreUWnPxgZa2frwzFgzamJl978ixWxPKpeNI9qQ1BO9ZBbg5YGVIYrNFFiw0j2B1mOx4u3tn1ntIW3cAJuOmFSI6U6NZy8JRGmkIvxjBzSqPTTUNfDNGtk00XiwrDHD69e0Zn5sX9W7ERf0QsWGK0tlj2YnaOty2MsRia96OgqGO+oqd6FggmIwPIb+2S0RghQLSRLyWFMKY68zZwugSLkl9r/TSrHPgJjGMWaIX1LyO8SbGrLToL7Cg0ptQrhosz1T2+zcdc+Z6fppTB2lF3cvF92b root@tower.ibm.nontoonyt.com"
state: present
- name: change sudoers file, uncomment nopasswd line for wheel
lineinfile:
dest: /etc/sudoers
regexp: '^#\s*\%wheel\s*ALL=\(ALL\)\s*NOPASSWD:\s*ALL.*$'
line: '%wheel ALL=(ALL) NOPASSWD: ALL'
- name: change sudoers file, comment out plain wheel line
lineinfile:
dest: /etc/sudoers
regexp: '^\%wheel\s*ALL=\(ALL\)\s*ALL.*$'
line: '#%wheel ALL=(ALL) ALL'