|
6 | 6 | - incus |
7 | 7 | install_recommends: false |
8 | 8 | state: present |
9 | | - register: install_deb |
| 9 | + register: incus_install_deb |
10 | 10 | when: 'ansible_distribution in ("Debian", "Ubuntu") and incus_roles | length > 0' |
11 | 11 |
|
12 | 12 | - name: Install the Incus package (rpm) |
13 | 13 | ansible.builtin.package: |
14 | 14 | name: |
15 | 15 | - incus |
16 | 16 | state: present |
17 | | - register: install_rpm |
| 17 | + register: incus_install_rpm |
18 | 18 | when: 'ansible_distribution == "CentOS" and incus_roles | length > 0' |
19 | 19 |
|
20 | 20 | - name: Install the Incus UI package (deb) |
|
49 | 49 | - name: List installed kernel images |
50 | 50 | ansible.builtin.command: >- |
51 | 51 | apt list linux-image-* --installed |
52 | | - register: linux_image_version |
| 52 | + register: incus_linux_image_version |
53 | 53 | changed_when: false |
54 | | - failed_when: "linux_image_version.rc != 0" |
| 54 | + failed_when: "incus_linux_image_version.rc != 0" |
55 | 55 | when: >- |
56 | 56 | incus_roles | length > 0 and 'zfs' in incus_init['storage'] | |
57 | 57 | dict2items | json_query('[].value.driver') and ansible_distribution == 'Debian' |
|
61 | 61 | name: |
62 | 62 | - linux-headers-{{ item | regex_replace('^linux-image-(.*)/.*$', '\1') }} |
63 | 63 | state: present |
64 | | - loop: "{{ linux_image_version.stdout_lines | default([]) | select('search', 'linux-image-[0-9]+.*/.*') }}" |
| 64 | + loop: "{{ incus_linux_image_version.stdout_lines | default([]) | select('search', 'linux-image-[0-9]+.*/.*') }}" |
65 | 65 | when: >- |
66 | 66 | incus_roles | length > 0 and 'zfs' in incus_init['storage'] | |
67 | 67 | dict2items | json_query('[].value.driver') and ansible_distribution == 'Debian' |
|
84 | 84 |
|
85 | 85 | - name: Set uid allocation |
86 | 86 | ansible.builtin.command: "usermod root --add-subuids 10000000-1009999999" |
87 | | - when: '(install_deb.changed or install_rpm.changed) and ansible_distribution == "CentOS"' |
| 87 | + when: '(incus_install_deb.changed or incus_install_rpm.changed) and ansible_distribution == "CentOS"' |
88 | 88 | changed_when: true |
89 | 89 |
|
90 | 90 | - name: Set gid allocation |
91 | 91 | ansible.builtin.command: "usermod root --add-subgids 10000000-1009999999" |
92 | | - when: '(install_deb.changed or install_rpm.changed) and ansible_distribution == "CentOS"' |
| 92 | + when: '(incus_install_deb.changed or incus_install_rpm.changed) and ansible_distribution == "CentOS"' |
93 | 93 | changed_when: true |
94 | 94 |
|
95 | 95 | - name: Enable incus socket unit |
96 | 96 | ansible.builtin.systemd: |
97 | 97 | enabled: true |
98 | 98 | name: incus.socket |
99 | 99 | state: started |
100 | | - when: 'install_deb.changed or install_rpm.changed' |
| 100 | + when: 'incus_install_deb.changed or incus_install_rpm.changed' |
101 | 101 |
|
102 | 102 | - name: Enable incus service unit |
103 | 103 | ansible.builtin.systemd: |
104 | 104 | enabled: true |
105 | 105 | name: incus.service |
106 | 106 | state: started |
107 | | - when: 'install_deb.changed or install_rpm.changed' |
| 107 | + when: 'incus_install_deb.changed or incus_install_rpm.changed' |
108 | 108 |
|
109 | 109 | - name: Enable incus startup unit |
110 | 110 | ansible.builtin.systemd: |
111 | 111 | enabled: true |
112 | 112 | name: incus-startup.service |
113 | 113 | state: started |
114 | | - when: 'install_deb.changed or install_rpm.changed' |
| 114 | + when: 'incus_install_deb.changed or incus_install_rpm.changed' |
115 | 115 |
|
116 | 116 | - name: Set client listen address |
117 | 117 | ansible.builtin.command: "incus --force-local config set core.https_address {{ incus_ip_address_or_default }}" |
118 | 118 | when: >- |
119 | | - (install_deb.changed or install_rpm.changed) and |
| 119 | + (incus_install_deb.changed or incus_install_rpm.changed) and |
120 | 120 | ("standalone" in incus_roles or ("cluster" in incus_roles and incus_servers[0] == inventory_hostname)) |
121 | 121 | notify: |
122 | 122 | - "Apply additional configuration" |
|
125 | 125 |
|
126 | 126 | - name: Set cluster listen address |
127 | 127 | ansible.builtin.command: "incus --force-local config set cluster.https_address {{ incus_ip_address_or_default }}" |
128 | | - when: '(install_deb.changed or install_rpm.changed) and "cluster" in incus_roles and incus_servers[0] == inventory_hostname' |
| 128 | + when: '(incus_install_deb.changed or incus_install_rpm.changed) and "cluster" in incus_roles and incus_servers[0] == inventory_hostname' |
129 | 129 | changed_when: true |
130 | 130 |
|
131 | 131 | - name: Set OVN NorthBound database |
|
137 | 137 | network.ovn.ca_cert="{{ lookup('file', ovn_config_dir + '/ca.crt') }}" |
138 | 138 | notify: Restart Incus |
139 | 139 | when: >- |
140 | | - (install_deb.changed or install_rpm.changed) and |
| 140 | + (incus_install_deb.changed or incus_install_rpm.changed) and |
141 | 141 | incus_ovn_northbound and |
142 | 142 | ("standalone" in incus_roles or ("cluster" in incus_roles and incus_servers[0] == inventory_hostname)) |
143 | 143 | changed_when: true |
|
149 | 149 | {% for k in item.value.config | default([]) %} {{ k }}={{ item.value.config[k] }}{% endfor %} |
150 | 150 | loop: "{{ incus_init['network'] | dict2items }}" |
151 | 151 | when: >- |
152 | | - (install_deb.changed or install_rpm.changed) and |
| 152 | + (incus_install_deb.changed or incus_install_rpm.changed) and |
153 | 153 | ("standalone" in incus_roles or ("cluster" in incus_roles and incus_servers[0] == inventory_hostname)) |
154 | 154 | changed_when: true |
155 | 155 |
|
|
158 | 158 | incus network set --property {{ item.key }} description="{{ item.value.description }}" |
159 | 159 | loop: "{{ incus_init['network'] | dict2items }}" |
160 | 160 | when: >- |
161 | | - (install_deb.changed or install_rpm.changed) and |
| 161 | + (incus_install_deb.changed or incus_install_rpm.changed) and |
162 | 162 | ("standalone" in incus_roles or ("cluster" in incus_roles and incus_servers[0] == inventory_hostname)) |
163 | 163 | and item.value.description is defined | default(None) |
164 | 164 | changed_when: true |
|
170 | 170 | {{ k }}={{ item.value.config[k] }}{% endfor %} |
171 | 171 | loop: "{{ incus_init['storage'] | dict2items }}" |
172 | 172 | when: > |
173 | | - (install_deb.changed or install_rpm.changed) and |
| 173 | + (incus_install_deb.changed or incus_install_rpm.changed) and |
174 | 174 | ("standalone" in incus_roles or ("cluster" in incus_roles and incus_servers[0] == inventory_hostname)) |
175 | 175 | changed_when: true |
176 | 176 |
|
177 | 177 | - name: Set storage pool description |
178 | 178 | ansible.builtin.command: "incus storage set --property {{ item.key }} description=\"{{ item.value.description }}\"" |
179 | 179 | loop: "{{ incus_init['storage'] | dict2items }}" |
180 | 180 | when: > |
181 | | - (install_deb.changed or install_rpm.changed) and |
| 181 | + (incus_install_deb.changed or incus_install_rpm.changed) and |
182 | 182 | ("standalone" in incus_roles or ("cluster" in incus_roles and incus_servers[0] == inventory_hostname)) and |
183 | 183 | item.value.description is defined | default(None) |
184 | 184 | changed_when: true |
|
187 | 187 | ansible.builtin.command: "incus profile device add default root disk path=/ pool={{ item }}" |
188 | 188 | loop: "{{ incus_init['storage'] | dict2items | json_query('[?value.default].key') }}" |
189 | 189 | when: > |
190 | | - (install_deb.changed or install_rpm.changed) and |
| 190 | + (incus_install_deb.changed or incus_install_rpm.changed) and |
191 | 191 | ("standalone" in incus_roles or ("cluster" in incus_roles and incus_servers[0] == inventory_hostname)) |
192 | 192 | changed_when: true |
193 | 193 |
|
194 | 194 | - name: Add network to default profile |
195 | 195 | ansible.builtin.command: "incus profile device add default eth0 nic network={{ item }} name=eth0" |
196 | 196 | loop: "{{ incus_init['network'] | dict2items | json_query('[?value.default].key') }}" |
197 | 197 | when: > |
198 | | - (install_deb.changed or install_rpm.changed) and |
| 198 | + (incus_install_deb.changed or incus_install_rpm.changed) and |
199 | 199 | ("standalone" in incus_roles or ("cluster" in incus_roles and incus_servers[0] == inventory_hostname)) |
200 | 200 | changed_when: true |
201 | 201 |
|
|
204 | 204 | incus --force-local config |
205 | 205 | set storage.linstor.controller_connection=http://{{ item }}:3370 |
206 | 206 | loop: "{{ ansible_play_hosts }}" |
207 | | - register: register_linstor_controller |
| 207 | + register: incus_register_linstor_controller |
208 | 208 | when: >- |
209 | 209 | "controller" in hostvars[item]["ansible_facts"]["linstor_roles"] and |
210 | 210 | ansible_distribution == "Ubuntu" and |
211 | 211 | ansible_distribution_release != "focal" |
212 | | - changed_when: "register_linstor_controller.rc == 0" |
| 212 | + changed_when: "incus_register_linstor_controller.rc == 0" |
213 | 213 |
|
214 | 214 | - name: Bootstrap the cluster |
215 | 215 | ansible.builtin.command: "incus --force-local cluster enable {{ inventory_hostname }}" |
216 | | - when: '(install_deb.changed or install_rpm.changed) and "cluster" in incus_roles and incus_servers[0] == inventory_hostname' |
| 216 | + when: '(incus_install_deb.changed or incus_install_rpm.changed) and "cluster" in incus_roles and incus_servers[0] == inventory_hostname' |
217 | 217 | changed_when: true |
218 | 218 |
|
219 | 219 | - name: Create join tokens |
220 | 220 | delegate_to: "{{ incus_servers[0] }}" |
221 | 221 | ansible.builtin.command: "incus --force-local --quiet cluster add {{ inventory_hostname }}" |
222 | | - register: cluster_add |
| 222 | + register: incus_cluster_add |
223 | 223 | notify: |
224 | 224 | - Wait 5s to avoid token use before valid |
225 | 225 | - Join the cluster |
226 | | - when: '(install_deb.changed or install_rpm.changed) and "cluster" in incus_roles and incus_servers[0] != inventory_hostname' |
| 226 | + when: '(incus_install_deb.changed or incus_install_rpm.changed) and "cluster" in incus_roles and incus_servers[0] != inventory_hostname' |
227 | 227 | changed_when: true |
0 commit comments