|
4 | 4 | - name: Assert VMs Variables
|
5 | 5 | assert:
|
6 | 6 | quiet: yes
|
7 |
| - that: "{{ item }} is defined" |
| 7 | + that: |
| 8 | + - "item.value is not none" |
| 9 | + - "item.value | string | length > 0" |
8 | 10 | fail_msg: >
|
9 |
| - You must specify {{ item }} |
10 |
| - with_items: |
11 |
| - - hostvars['terraform_node'] |
12 |
| - - hostvars['terraform_node']['ansible_host'] |
13 |
| - - hostvars['terraform_node']['ansible_connection'] |
14 |
| - - ansible_host |
15 |
| - - base_deploy_path |
16 |
| - - disk_source |
17 |
| - - network_interfaces |
18 |
| - - pool_name |
19 |
| - - ssh_password |
20 |
| - - ssh_port |
21 |
| - - ssh_public_key_file |
22 |
| - - ssh_user |
23 |
| - - state_save_file |
24 |
| - - vm_autostart |
| 11 | + You must specify {{ item.key }} |
| 12 | + loop: "{{ _mandantory_variables | dict2items }}" |
| 13 | + vars: |
| 14 | + _mandantory_variables: |
| 15 | + "hostvars['terraform_node']": "{{ hostvars['terraform_node'] | default }}" |
| 16 | + "hostvars['terraform_node']['ansible_host']": "{{ hostvars['terraform_node']['ansible_host'] | default }}" |
| 17 | + "hostvars['terraform_node']['ansible_connection']": "{{ hostvars['terraform_node']['ansible_connection'] | default }}" |
| 18 | + "ansible_host": "{{ ansible_host | default }}" |
| 19 | + "base_deploy_path": "{{ base_deploy_path | default }}" |
| 20 | + "disk_source": "{{ disk_source | default }}" |
| 21 | + "network_interfaces": "{{ network_interfaces | default }}" |
| 22 | + "pool_name": "{{ pool_name | default }}" |
| 23 | + "ssh_password": "{{ ssh_password | default }}" |
| 24 | + "ssh_port": "{{ ssh_port | default }}" |
| 25 | + "ssh_public_key_file": "{{ ssh_public_key_file | default }}" |
| 26 | + "ssh_user": "{{ ssh_user | default }}" |
| 27 | + "state_save_file": "{{ state_save_file | default }}" |
| 28 | + "vm_autostart": "{{ vm_autostart | default }}" |
25 | 29 |
|
26 |
| -# Verifiy the correctness of the parameters. |
| 30 | +# Verify the correctness of the parameters. |
27 | 31 | - name: Validate 'ssh_port' parameter
|
28 | 32 | assert:
|
29 | 33 | quiet: yes
|
|
33 | 37 | fail_msg: >
|
34 | 38 | You are trying to use an unsupported ssh_port value.
|
35 | 39 |
|
36 |
| -# Verifiy the correctness of the parameters. |
| 40 | +# Verify the correctness of the parameters. |
37 | 41 | - name: Validate 'ansible_port' parameter
|
38 | 42 | assert:
|
39 | 43 | quiet: yes
|
|
50 | 54 | assert:
|
51 | 55 | quiet: yes
|
52 | 56 | that:
|
53 |
| - - "{{ item }}" |
| 57 | + - "os_family is defined" |
| 58 | + - "os_family in os_family_support" |
54 | 59 | fail_msg: >
|
55 | 60 | You must specify the os_family for host {{ inventory_hostname }},
|
56 | 61 | supported values are: {{ os_family_support }}
|
57 |
| - with_items: |
58 |
| - - "os_family is defined" |
59 |
| - - "os_family in os_family_support" |
60 | 62 |
|
61 | 63 | # Ensure that the hypervisor variable has been set for current host.
|
62 | 64 | - name: Assert hypervisor variable
|
63 | 65 | assert:
|
64 | 66 | quiet: yes
|
65 | 67 | that:
|
66 |
| - - "{{ item }}" |
| 68 | + - "hypervisor is defined" |
| 69 | + - "hostvars[hypervisor]['ansible_host'] is defined" |
67 | 70 | fail_msg: >
|
68 | 71 | You must specify the hyperisor value for host {{ inventory_hostname }}
|
69 |
| - with_items: |
70 |
| - - "hypervisor is defined" |
71 |
| - - "hostvars[hypervisor]['ansible_host'] is defined" |
72 | 72 |
|
73 | 73 | # Verifiy the correctness of the parameters.
|
74 | 74 | - name: Validate 'cpu' parameter
|
|
117 | 117 | assert:
|
118 | 118 | quiet: yes
|
119 | 119 | that:
|
120 |
| - - "{{ item }}.name is defined" |
121 |
| - - "{{ item }}.type is defined" |
122 |
| - - "{{ item }}.ip is defined" |
123 |
| - - "{{ item }}.gw is defined" |
124 |
| - - "{{ item }}.dns is defined" |
| 120 | + - "item.name is defined" |
| 121 | + - "item.type is defined" |
| 122 | + - "item.ip is defined" |
| 123 | + - "item.gw is defined" |
| 124 | + - "item.dns is defined" |
125 | 125 | fail_msg: >
|
126 | 126 | Incomplete interface declaration for {{ item }}, missing a mandatory var
|
127 | 127 | with_items:
|
|
132 | 132 | assert:
|
133 | 133 | quiet: yes
|
134 | 134 | that:
|
135 |
| - - "{{ item }}.type == 'nat' or |
136 |
| - {{ item }}.type == 'macvtap' or |
137 |
| - {{ item }}.type == 'bridge'" |
| 135 | + - "item.type == 'nat' or |
| 136 | + item.type == 'macvtap' or |
| 137 | + item.type == 'bridge'" |
138 | 138 | fail_msg: >
|
139 | 139 | Unsupported value for interface type.
|
140 | 140 | with_items:
|
|
145 | 145 | assert:
|
146 | 146 | quiet: yes
|
147 | 147 | that:
|
148 |
| - - "{{ item }}.ip | ipaddr" |
| 148 | + - "item.ip | ipaddr" |
149 | 149 | fail_msg: >
|
150 | 150 | Invalid interface ip address.
|
151 | 151 | when:
|
|
158 | 158 | assert:
|
159 | 159 | quiet: yes
|
160 | 160 | that:
|
161 |
| - - "{{ item }}.gw | ipaddr" |
| 161 | + - "item.gw | ipaddr" |
162 | 162 | fail_msg: >
|
163 | 163 | Invalid interface gateway address.
|
164 | 164 | when:
|
|
171 | 171 | assert:
|
172 | 172 | quiet: yes
|
173 | 173 | that:
|
174 |
| - - "{{ item.dns }} | length > 0" |
| 174 | + - "item.dns | length > 0" |
175 | 175 | fail_msg: >
|
176 | 176 | Incomplete interface dns specification.
|
177 | 177 | when:
|
|
190 | 190 | assert:
|
191 | 191 | quiet: yes
|
192 | 192 | that:
|
193 |
| - - "{{ item }}.size is defined" |
194 |
| - - "{{ item }}.pool is defined" |
195 |
| - - "{{ item }}.format is defined" |
196 |
| - - "{{ item }}.mount_point is defined" |
197 |
| - - "{{ item }}.encryption is defined" |
| 193 | + - "item.size is defined" |
| 194 | + - "item.pool is defined" |
| 195 | + - "item.format is defined" |
| 196 | + - "item.mount_point is defined" |
| 197 | + - "item.encryption is defined" |
198 | 198 | fail_msg: >
|
199 | 199 | You must specify {{ item }} when data_disks is defined
|
200 | 200 | with_items:
|
|
208 | 208 | assert:
|
209 | 209 | quiet: yes
|
210 | 210 | that:
|
211 |
| - - "{{ item }}.size | int" |
212 |
| - - "{{ item }}.size > 0" |
| 211 | + - "item.size | int" |
| 212 | + - "item.size > 0" |
213 | 213 | fail_msg: >
|
214 | 214 | You are trying to use an unsupported size value.
|
215 | 215 | with_items:
|
|
223 | 223 | assert:
|
224 | 224 | quiet: yes
|
225 | 225 | that:
|
226 |
| - - "{{ item }}.pool | length > 0" |
| 226 | + - "item.pool | length > 0" |
227 | 227 | fail_msg: >
|
228 | 228 | You are trying to use an unsupported pool value.
|
229 | 229 | with_items:
|
|
236 | 236 | assert:
|
237 | 237 | quiet: yes
|
238 | 238 | that:
|
239 |
| - - "{{ item }}.format in {{ supported_fs }}" |
240 |
| - - "{{ item }}.format | length > 0" |
| 239 | + - "item.format in {{ supported_fs }}" |
| 240 | + - "item.format | length > 0" |
241 | 241 | fail_msg: >
|
242 | 242 | You must specify a valid disk format for host {{ inventory_hostname }},
|
243 | 243 | supported values are: {{ supported_fs }}
|
|
252 | 252 | assert:
|
253 | 253 | quiet: yes
|
254 | 254 | that:
|
255 |
| - - '{{ item }}.mount_point == "none" or {{ item }}.mount_point | regex_search("^/\\w+")' |
256 |
| - - "{{ item }}.mount_point | length > 0" |
| 255 | + - 'item.mount_point == "none" or item.mount_point | regex_search("^/\\w+")' |
| 256 | + - "item.mount_point | length > 0" |
257 | 257 | fail_msg: >
|
258 | 258 | You are trying to use an unsupported mount_point value.
|
259 | 259 | with_items:
|
|
267 | 267 | assert:
|
268 | 268 | quiet: yes
|
269 | 269 | that:
|
270 |
| - - not {{ item }}.encryption |
| 270 | + - not item.encryption |
271 | 271 | fail_msg: >
|
272 | 272 | You are trying to use an unsupported encryption value. FreeBSD family and CloudInit images doesn't support encryption.
|
273 | 273 | with_items:
|
|
282 | 282 | assert:
|
283 | 283 | quiet: yes
|
284 | 284 | that:
|
285 |
| - - "{{ item.encryption }} | type_debug == 'bool'" |
| 285 | + - "item.encryption | type_debug == 'bool'" |
286 | 286 | fail_msg: >
|
287 | 287 | You are trying to use an unsupported encryption value. Possible values could be 'True' or 'False'.
|
288 | 288 | with_items:
|
|
0 commit comments