217 lines
6.4 KiB
YAML
217 lines
6.4 KiB
YAML
---
|
|
|
|
- name: Fetch a CentOS image to use for libvirt 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 libvirt 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 libvirt 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 libvirt nodepool IP addresses
|
|
script: "get-domain-ip.sh subnode-0"
|
|
register: "subnode_0_ip_result"
|
|
until: "subnode_0_ip_result is 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 "append domain-name-servers {{ custom_nameserver|default('8.8.8.8') }};" >> /etc/dhcp/dhclient.conf
|
|
become: true
|
|
|
|
- name: Get libvirt nodepool IP addresses
|
|
script: "get-domain-ip.sh subnode-1"
|
|
register: "subnode_1_ip_result"
|
|
until: "subnode_1_ip_result is 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 "append domain-name-servers {{ custom_nameserver|default('8.8.8.8') }};" >> /etc/dhcp/dhclient.conf
|
|
become: true
|
|
|
|
- name: Create inventory suitable for zuul-jobs/multinode
|
|
template:
|
|
src: "{{ zuul_hosts_template }}"
|
|
dest: "{{ local_working_dir }}/zuul-hosts.yaml"
|
|
mode: 0755
|