This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
/
fake_nodepool.yml
210 lines (184 loc) · 6.26 KB
/
fake_nodepool.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
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
---
- name: Fetch a CentOS image to use for fake nodepool nodes
include_role:
name: fetch-images
- name: Resize undercloud image (create target image)
command: >
qemu-img create -f qcow2 -o preallocation=off
'{{ working_dir }}/undercloud-resized.qcow2'
'80G'
- name: Resize undercloud image (call virt-resize)
command: >
virt-resize --expand /dev/sda1
'{{ working_dir }}/undercloud.qcow2'
'{{ working_dir }}/undercloud-resized.qcow2'
environment:
LIBGUESTFS_BACKEND: direct
- name: Rename resized image to original name
command: >
mv -f '{{ working_dir }}/undercloud-resized.qcow2'
'{{ working_dir }}/undercloud.qcow2'
- name: Calculate password hash
no_log: true
shell: >
import crypt;
print crypt.crypt("{{ vm_pass }}", "$1$SecretSalt$")
args:
executable: /usr/bin/python
register: hash
- name: Copy generated password to file
local_action: copy content={{ hash.stdout }} dest="{{ working_dir }}/pwtemp" mode=0600
- name: Inject password into the image
command: >
virt-customize -a {{ working_dir }}/undercloud.qcow2
--root-password file:"{{ working_dir }}/pwtemp"
environment:
LIBGUESTFS_BACKEND: direct
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
register: root_password
- name: Remove root password file
file:
path: "{{ working_dir }}/pwtemp"
state: absent
- name: Resize the filesystem
command: >
virt-customize -a {{ working_dir }}/undercloud.qcow2
--run-command 'xfs_growfs /'
environment:
LIBGUESTFS_BACKEND: direct
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
- name: Disable cloud-init
command: >
virt-customize -a {{ working_dir }}/undercloud.qcow2
--run-command "grubby --update-kernel=ALL --args=\"cloud-init=disabled\""
environment:
LIBGUESTFS_BACKEND: direct
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
- name: Inject ssh public key into the image
command: >
virt-customize -a {{ working_dir }}/undercloud.qcow2
--mkdir /root/.ssh/
--upload '{{ pub_key }}:/root/.ssh/authorized_keys'
--run-command 'chown -R root:root /root/.ssh'
--run-command 'chmod 0700 /root/.ssh'
--run-command 'chmod 0600 /root/.ssh/authorized_keys'
--selinux-relabel
environment:
LIBGUESTFS_BACKEND: direct
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
- name: Add zuul user to the image
command: >
virt-customize -a {{ working_dir }}/undercloud.qcow2
--run-command 'useradd zuul'
--mkdir /home/zuul/.ssh
--run-command 'cp /root/.ssh/authorized_keys /home/zuul/.ssh/'
--run-command 'chown -R zuul:zuul /home/zuul/.ssh'
--run-command 'chmod 0700 /home/zuul/.ssh'
--run-command 'chmod 0600 /home/zuul/.ssh/authorized_keys'
--run-command 'echo "zuul ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/zuul'
--run-command 'chmod 0440 /etc/sudoers.d/zuul'
--selinux-relabel
environment:
LIBGUESTFS_BACKEND: direct
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
- debug:
msg: "Add basic packages we need to the image"
- environment:
LIBVIRT_DEFAULT_URI: "{{ libvirt_uri }}"
block:
# Create libvirt volumes and upload them to libvirt.
- name: Create fake nodepool volumes
command: >
virsh vol-create-as {{ libvirt_volume_pool}}
{{ item.name }}.qcow2
{{ flavors[item.flavor].disk }}G --format qcow2
with_items: "{{ overcloud_nodes }}"
- name: Upload the volume to storage pool
command: >
virsh -k 0 vol-upload --pool '{{ libvirt_volume_pool }}'
'{{ item.name }}.qcow2'
'{{ local_working_dir }}/undercloud.qcow2'
async: 600
poll: 10
with_items: "{{ overcloud_nodes }}"
- name: Start fake nodepool nodes
virt:
name: "{{ item.name }}"
command: start
autostart: true
state: running
uri: "{{ libvirt_uri }}"
with_items: "{{ overcloud_nodes }}"
## need to find a way to make these next tasks generic
- name: Get fake nodepool IP addresses
script: "get-undercloud-ip.sh subnode-0"
register: "subnode_0_ip_result"
until: "subnode_0_ip_result|success"
retries: 20
delay: 10
- name: Set_fact for undercloud ip
set_fact:
subnode_0_ip: "{{ subnode_0_ip_result.stdout_lines[0] }}"
cacheable: true
- name: Wait until ssh is available
wait_for:
host: "{{ subnode_0_ip }}"
state: started
port: 22
timeout: 600
- name: Add subnode-0 to inventory
add_host:
name: subnode-0
groups: subnodes
ansible_host: "{{ subnode_0_ip }}"
ansible_fqdn: "{{ subnode_0_ip }}"
ansible_user: zuul
ansible_private_key_file: "~/.ssh/id_rsa"
subnode_private_ip: "{{ subnode_0_ip }}"
subnode_public_ip: "{{ subnode_0_ip }}"
- name: Set hostname correctly for subnode-0
delegate_to: subnode-0
shell: >
echo "127.0.0.1 subnode-0 localhost" > /etc/hosts;
echo "HOSTNAME=subnode-0" >> /etc/sysconfig/network;
echo "subnode-0" > /etc/hostname;
hostnamectl set-hostname subnode-0;
echo "nameserver {{ custom_nameserver|default('8.8.8.8') }} " >> /etc/resolv.conf;
echo "supersede domain-name-servers {{ custom_nameserver|default('8.8.8.8') }};" >> /etc/dhcp/dhclient.conf
become: true
- name: Get fake nodepool IP addresses
script: "get-undercloud-ip.sh subnode-1"
register: "subnode_1_ip_result"
until: "subnode_1_ip_result|success"
retries: 20
delay: 10
- name: Set_fact for undercloud ip
set_fact:
subnode_1_ip: "{{ subnode_1_ip_result.stdout_lines[0] }}"
cacheable: true
- name: Wait until ssh is available
wait_for:
host: "{{ subnode_1_ip }}"
state: started
port: 22
timeout: 600
- name: Add subnode-1 to inventory
add_host:
name: subnode-1
groups: subnodes
ansible_host: "{{ subnode_1_ip }}"
ansible_fqdn: "{{ subnode_1_ip }}"
ansible_user: zuul
ansible_private_key_file: "~/.ssh/id_rsa"
subnode_private_ip: "{{ subnode_1_ip }}"
subnode_public_ip: "{{ subnode_1_ip }}"
- name: Set hostname correctly for subnode-1
delegate_to: subnode-1
shell: >
echo "127.0.0.1 subnode-1 localhost" > /etc/hosts;
echo "HOSTNAME=subnode-1" >> /etc/sysconfig/network;
echo "subnode-1" > /etc/hostname;
hostnamectl set-hostname subnode-1;
echo "nameserver {{ custom_nameserver|default('8.8.8.8') }} " >> /etc/resolv.conf;
echo "supersede domain-name-servers {{ custom_nameserver|default('8.8.8.8') }};" >> /etc/dhcp/dhclient.conf
become: true