-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_gce_instances.yml
96 lines (85 loc) · 2.81 KB
/
create_gce_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
- name: create instance(s) on gce
hosts: localhost
remote_user: root
gather_facts: no
vars:
network:
selfLink: projects/ansible-automates-20191211/global/networks/default
ansible_python_interpreter: /var/lib/awx/venv/ansible/bin/python
tasks:
- name: create instance(s) on gce
gcp_compute_instance:
auth_kind: serviceaccount
name: automates2019gce
project: ansible-automates-20191211
labels:
event: "{{ tag }}"
machine_type: n1-standard-1
disks:
- auto_delete: yes
boot: yes
initialize_params:
disk_size_gb: 20
source_image: projects/rhel-cloud/global/images/rhel-8-v20191121
network_interfaces:
- network: "{{ network }}"
access_configs:
- name: External NAT
type: ONE_TO_ONE_NAT
state: present
status: RUNNING
zone: europe-west2-a
tags:
items:
- http-server
register: gce
delegate_to: localhost
- name: show me the gce variable
debug:
var: gce
verbosity: 2
- name: set public_ip fact
set_fact:
public_ip: "{{ gce.networkInterfaces[0].accessConfigs[0].natIP }}"
- name: show me the natIP variable
debug:
var: public_ip
verbosity: 2
- name: add new hosts to tmpgroup
add_host:
name: "{{ public_ip }}"
groups: tmpgroup
- name: check connectivity
hosts: tmpgroup
remote_user: mburgerh
become: yes
gather_facts: no
vars:
ansible_python_interpreter: /usr/libexec/platform-python
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 [email protected]"
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'