|
1 | 1 | ---
|
2 | 2 |
|
3 |
| -- name: "Power: Load all variables" |
4 |
| - include_vars: |
5 |
| - file: "{{ ansible_inventory_sources[0] }}/group_vars/all.yaml" |
6 |
| - register: global_vars |
7 |
| - changed_when: false |
8 |
| - delegate_to: localhost |
9 |
| - |
10 |
| -- name: "Power: Load VMs variables" |
11 |
| - include_vars: |
12 |
| - file: "{{ ansible_inventory_sources[0] }}/host_vars/{{ vm }}.yaml" |
13 |
| - loop: "{{ vms }}" |
14 |
| - loop_control: |
15 |
| - loop_var: vm |
16 |
| - register: vms_vars |
17 |
| - changed_when: false |
18 |
| - delegate_to: localhost |
19 |
| - |
20 | 3 | - name: "Power: Power off VMs"
|
21 | 4 | azure.azcollection.azure_rm_virtualmachine:
|
22 |
| - name: "{{ vm_var.vm.split('.')[0] }}" |
| 5 | + name: "{{ vm.split('.')[0] }}" |
23 | 6 | allocated: no
|
24 | 7 | resource_group: "{{ azure_resource_group_name }}"
|
25 | 8 | client_id: "{{ azure_client_id }}"
|
26 | 9 | secret: "{{ azure_client_secret }}"
|
27 | 10 | subscription_id: "{{ azure_subscription_id }}"
|
28 | 11 | tenant: "{{ azure_tenant_id }}"
|
29 |
| - loop: "{{ vms_vars.results }}" |
| 12 | + loop: "{{ vms }}" |
30 | 13 | loop_control:
|
31 |
| - loop_var: vm_var |
| 14 | + loop_var: vm |
32 | 15 | changed_when: false
|
33 | 16 | when:
|
34 |
| - - global_vars.ansible_facts.azure_vm_keep_running is defined |
35 |
| - - not global_vars.ansible_facts.azure_vm_keep_running |
36 |
| - - vm_var.ansible_facts.azure_vm_keep_running is not defined or |
37 |
| - not vm_var.ansible_facts.azure_vm_keep_running |
| 17 | + - hostvars[vm].azure_vm_keep_running is defined |
| 18 | + - not hostvars[vm].azure_vm_keep_running |
38 | 19 | delegate_to: localhost
|
39 | 20 | register: azure_power_off_async_results
|
40 | 21 | async: 600
|
|
43 | 24 | - name: "Wait for VMs to be unreachable"
|
44 | 25 | wait_for:
|
45 | 26 | port: 22
|
46 |
| - host: "{{ vm_var.vm }}" |
| 27 | + host: "{{ vm }}" |
47 | 28 | state: stopped
|
48 | 29 | connection: local
|
49 |
| - loop: "{{ vms_vars.results }}" |
| 30 | + loop: "{{ vms }}" |
50 | 31 | loop_control:
|
51 |
| - loop_var: vm_var |
| 32 | + loop_var: vm |
52 | 33 | retries: 60
|
53 | 34 | delay: 10
|
54 | 35 | when:
|
55 |
| - - global_vars.ansible_facts.azure_vm_keep_running is defined |
56 |
| - - not global_vars.ansible_facts.azure_vm_keep_running |
57 |
| - - vm_var.ansible_facts.azure_vm_keep_running is not defined or |
58 |
| - not vm_var.ansible_facts.azure_vm_keep_running |
| 36 | + - hostvars[vm].azure_vm_keep_running is defined |
| 37 | + - not hostvars[vm].azure_vm_keep_running |
| 38 | + delegate_to: localhost |
0 commit comments