12 changed files with 191 additions and 115 deletions
@ -0,0 +1,2 @@ |
|||
collections: |
|||
- name: community.libvirt |
|||
@ -0,0 +1,55 @@ |
|||
- name: Add the libvirt server to the inventory |
|||
hosts: localhost |
|||
gather_facts: no |
|||
tasks: |
|||
- add_host: |
|||
hostname: '{{ lookup("env", "LIBVIRT_SERVER") }}' |
|||
ansible_host: '{{ lookup("env", "LIBVIRT_SERVER") }}' |
|||
ansible_user: '{{ lookup("env", "LIBVIRT_USER") }}' |
|||
groups: hypervisor |
|||
|
|||
- name: Start the OpenShift cluster |
|||
hosts: hypervisor |
|||
gather_facts: no |
|||
become: yes |
|||
vars: |
|||
lb: '{{ nodes | selectattr("role", "eq", "lb") | first }}' |
|||
storage: '{{ nodes | selectattr("role", "eq", "storage") | first }}' |
|||
workers: '{{ nodes | selectattr("role", "eq", "worker") | list }}' |
|||
masters: '{{ nodes | selectattr("role", "eq", "master") | list }}' |
|||
tasks: |
|||
- name: Configure name resolution for the cluster |
|||
template: |
|||
src: dnsmasq.conf.j2 |
|||
dest: /etc/NetworkManager/dnsmasq.d/zone-{{ network_domain }}.conf |
|||
|
|||
- name: Restart dnsmasq |
|||
command: pkill -f [d]nsmasq.*--enable-dbus=org.freedesktop.NetworkManager.dnsmasq |
|||
|
|||
- name: Start the Load Balancer and the Storage |
|||
community.libvirt.virt: |
|||
name: '{{ item.name }}' |
|||
state: running |
|||
loop: |
|||
- '{{ lb }}' |
|||
- '{{ storage }}' |
|||
loop_control: |
|||
label: "{{ item.name }}" |
|||
|
|||
- name: Wait for the Load Balancer to appear |
|||
wait_for: |
|||
port: 443 |
|||
host: '{{ lb.ip[1] }}' |
|||
|
|||
- name: Wait for the NFS Server to appear |
|||
wait_for: |
|||
port: 2049 |
|||
host: '{{ storage.ip }}' |
|||
|
|||
- name: Start the Workers and the Masters |
|||
community.libvirt.virt: |
|||
name: '{{ item.name }}' |
|||
state: running |
|||
loop: '{{ masters + workers }}' |
|||
loop_control: |
|||
label: "{{ item.name }}" |
|||
@ -0,0 +1,77 @@ |
|||
- name: Add the libvirt server to the inventory |
|||
hosts: localhost |
|||
gather_facts: no |
|||
tasks: |
|||
- add_host: |
|||
hostname: '{{ lookup("env", "LIBVIRT_SERVER") }}' |
|||
ansible_host: '{{ lookup("env", "LIBVIRT_SERVER") }}' |
|||
ansible_user: '{{ lookup("env", "LIBVIRT_USER") }}' |
|||
groups: hypervisor |
|||
|
|||
- name: Stop the OpenShift cluster |
|||
hosts: hypervisor |
|||
gather_facts: no |
|||
become: yes |
|||
vars: |
|||
lb: '{{ nodes | selectattr("role", "eq", "lb") | first }}' |
|||
storage: '{{ nodes | selectattr("role", "eq", "storage") | first }}' |
|||
workers: '{{ nodes | selectattr("role", "eq", "worker") | list }}' |
|||
masters: '{{ nodes | selectattr("role", "eq", "master") | list }}' |
|||
tasks: |
|||
- name: Stop the workers |
|||
community.libvirt.virt: |
|||
name: '{{ item.name }}' |
|||
state: shutdown |
|||
loop: '{{ workers }}' |
|||
loop_control: |
|||
label: "{{ item.name }}" |
|||
|
|||
- name: Wait for the workers to shutdown |
|||
community.libvirt.virt: |
|||
name: '{{ item.name }}' |
|||
command: info |
|||
register: vm |
|||
until: "vm[item.name].state == 'shutdown'" |
|||
retries: 24 |
|||
delay: 5 |
|||
loop: '{{ workers }}' |
|||
loop_control: |
|||
label: "{{ item.name }}" |
|||
|
|||
- name: Stop the masters |
|||
community.libvirt.virt: |
|||
name: '{{ item.name }}' |
|||
state: shutdown |
|||
loop: '{{ masters }}' |
|||
loop_control: |
|||
label: "{{ item.name }}" |
|||
|
|||
- name: Wait for the masters to shutdown |
|||
community.libvirt.virt: |
|||
name: '{{ item.name }}' |
|||
command: info |
|||
register: vm |
|||
until: "vm[item.name].state == 'shutdown'" |
|||
retries: 24 |
|||
delay: 5 |
|||
loop: '{{ masters }}' |
|||
loop_control: |
|||
label: "{{ item.name }}" |
|||
|
|||
- name: Stop the remaining nodes |
|||
community.libvirt.virt: |
|||
name: '{{ item.name }}' |
|||
state: shutdown |
|||
loop: |
|||
- '{{ lb }}' |
|||
- '{{ storage }}' |
|||
loop_control: |
|||
label: "{{ item.name }}" |
|||
|
|||
- name: Unconfigure name resolution for the cluster |
|||
file: |
|||
path: /etc/NetworkManager/dnsmasq.d/zone-{{ network_domain }}.conf |
|||
state: absent |
|||
|
|||
- name: Restart dnsmasq |
|||
command: pkill -f [d]nsmasq.*--enable-dbus=org.freedesktop.NetworkManager.dnsmasq |
|||
@ -0,0 +1 @@ |
|||
server=/{{ network_domain }}/{{ dns_server }} |
|||
@ -0,0 +1,6 @@ |
|||
[hypervisor] |
|||
|
|||
[hypervisor:vars] |
|||
network_domain=${network_domain} |
|||
dns_server=${dns_server} |
|||
nodes=${jsonencode(nodes)} |
|||
@ -1,30 +0,0 @@ |
|||
#!/bin/sh |
|||
|
|||
set -Eeuo pipefail |
|||
trap "exit" INT |
|||
|
|||
function start () { |
|||
for i; do |
|||
sudo virsh start "$i" || true |
|||
done |
|||
} |
|||
|
|||
function wait_for_ip () { |
|||
echo "Waiting for $1 to come online..." |
|||
while ! ping -n -c4 -i.2 $2 -q &>/dev/null; do |
|||
sleep 1 |
|||
done |
|||
} |
|||
|
|||
%{for host, ip in others~} |
|||
start "${host}" |
|||
wait_for_ip "${host}" "${ip}" |
|||
%{endfor~} |
|||
|
|||
%{for host, ip in masters~} |
|||
start "${host}" |
|||
%{endfor~} |
|||
|
|||
%{for host, ip in workers~} |
|||
start "${host}" |
|||
%{endfor~} |
|||
@ -1,22 +0,0 @@ |
|||
#!/bin/sh |
|||
|
|||
set -Eeuo pipefail |
|||
trap "exit" INT |
|||
|
|||
function stop_group () { |
|||
for i; do |
|||
sudo virsh shutdown "$i" --mode=agent || true |
|||
done |
|||
|
|||
for i; do |
|||
echo "Waiting for $i to shutdown..." |
|||
while sudo virsh list --name | egrep -q "^$i\$"; do |
|||
sleep 1 |
|||
continue |
|||
done |
|||
done |
|||
} |
|||
|
|||
stop_group %{for host in workers}"${host}" %{endfor} |
|||
stop_group %{for host in masters}"${host}" %{endfor} |
|||
stop_group "${lb}" "${storage}" |
|||
Loading…
Reference in new issue