-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.yml
114 lines (100 loc) · 3.82 KB
/
main.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
---
# tasks file for bootstrap
- name: "Assert mandatory variables are defined"
ansible.builtin.assert:
that:
- machines is defined
- ssh_key_path != ""
- name: Check if the ~/.ssh directory exists, if not create it
ansible.builtin.file:
path: "{{ ssh_key_path }}"
state: directory
mode: '0755'
- name: Checking if ssh key exists and if not generate a new one
community.crypto.openssh_keypair:
path: "{{ ssh_key_path }}/{{ ssh_key_name }}"
- name: Create the files directory in bootstrap role
ansible.builtin.file:
path: "./roles/bootstrap/files"
state: directory
mode: '0755'
- name: Template the ignite-vm.yaml configuratin file for machines
ansible.builtin.template:
src: ignite-vm.yaml.j2
dest: "./roles/bootstrap/files/{{ item.name }}.yaml"
mode: '0755'
loop:
"{{ machines }}"
when: item.arch == ansible_facts["architecture"]
delegate_to: localhost
- name: Template the ignite-vm.yaml configuratin file for builders
ansible.builtin.template:
src: ignite-vm.yaml.j2
dest: "./roles/bootstrap/files/{{ item.name }}.yaml"
mode: '0755'
loop:
"{{ builders }}"
when: item.arch == ansible_facts["architecture"]
delegate_to: localhost
- name: Pull kernel and rootfs OCI images
block:
- name: Pull kernel OCI images
community.docker.docker_image:
name: "{{ item.kernel }}"
source: pull
force_source: true
loop: "{{ machines | union(builders) }}"
when: item.arch == ansible_facts["architecture"]
- name: Pull rootfs OCI images
community.docker.docker_image:
name: "{{ item.rootfs }}"
source: pull
force_source: true
loop: "{{ machines | union(builders) }}"
when: item.arch == ansible_facts["architecture"]
- name: Create virtual machines run_id={{ run_id }}
ansible.builtin.command:
cmd: ignite run --config "./roles/bootstrap/files/{{ item.name }}.yaml" --runtime docker
register: ignite_run
changed_when: ignite_run.rc == 0
loop: "{{ machines | union(builders) }}"
when: item.arch == ansible_facts["architecture"]
become: true
- name: Wait for the VMs to be running run_id={{ run_id }} # noqa: risky-shell-pipe
ansible.builtin.shell: |
if test -v BASH; then set -o pipefail; fi
ignite ps -f \{\{.ObjectMeta.Name\}\}={{ item.name }}-{{ run_id }},\{\{.Status.Running\}\}=true | wc -l
register: result
until: result.stdout | int == 2
retries: 5
delay: 10
loop: "{{ machines | union(builders) }}"
when: item.arch == ansible_facts["architecture"]
changed_when: result.stdout | int == 2
become: true
- name: Get IP of the VMs(machines) and register them in a variable run_id={{ run_id }}
ansible.builtin.command:
cmd: ignite ps -f \{\{.ObjectMeta.Name\}\}={{ item.name }}-{{ run_id }},\{\{.Status.Running\}\}=true -t \{\{.Status.Network.IPAddresses\}\}
register: machine_ips
failed_when: machine_ips.stdout_lines | length != 1
changed_when: machine_ips.stdout_lines | length == 1
loop: "{{ machines }}"
when: item.arch == ansible_facts["architecture"]
become: true
- name: Get IP of the VMs(builders) and register them in a variable run_id={{ run_id }}
ansible.builtin.command:
cmd: ignite ps -f \{\{.ObjectMeta.Name\}\}={{ item.name }}-{{ run_id }},\{\{.Status.Running\}\}=true -t \{\{.Status.Network.IPAddresses\}\}
register: builders_ips
failed_when: builders_ips.stdout_lines | length != 1
changed_when: builders_ips.stdout_lines | length == 1
loop: "{{ builders }}"
when: item.arch == ansible_facts["architecture"]
become: true
- name: Template the inventory.ini.j2 configuration file to invetory.ini
ansible.builtin.template:
src: inventory.ini.j2
dest: inventory.ini
mode: '0755'
delegate_to: localhost
- name: Refresh inventory to ensure that the new generated one is used
ansible.builtin.meta: refresh_inventory