Skip to content

Commit 8887b6c

Browse files
committed
Simplify and fix azure role
Simplified and fixed the azure role in order to work seamlessly via command-line Ansible and via AWX.
1 parent 6af5c87 commit 8887b6c

File tree

1 file changed

+11
-31
lines changed

1 file changed

+11
-31
lines changed

roles/azure/tasks/power_off.yaml

+11-31
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
11
---
22

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-
203
- name: "Power: Power off VMs"
214
azure.azcollection.azure_rm_virtualmachine:
22-
name: "{{ vm_var.vm.split('.')[0] }}"
5+
name: "{{ vm.split('.')[0] }}"
236
allocated: no
247
resource_group: "{{ azure_resource_group_name }}"
258
client_id: "{{ azure_client_id }}"
269
secret: "{{ azure_client_secret }}"
2710
subscription_id: "{{ azure_subscription_id }}"
2811
tenant: "{{ azure_tenant_id }}"
29-
loop: "{{ vms_vars.results }}"
12+
loop: "{{ vms }}"
3013
loop_control:
31-
loop_var: vm_var
14+
loop_var: vm
3215
changed_when: false
3316
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
3819
delegate_to: localhost
3920
register: azure_power_off_async_results
4021
async: 600
@@ -43,16 +24,15 @@
4324
- name: "Wait for VMs to be unreachable"
4425
wait_for:
4526
port: 22
46-
host: "{{ vm_var.vm }}"
27+
host: "{{ vm }}"
4728
state: stopped
4829
connection: local
49-
loop: "{{ vms_vars.results }}"
30+
loop: "{{ vms }}"
5031
loop_control:
51-
loop_var: vm_var
32+
loop_var: vm
5233
retries: 60
5334
delay: 10
5435
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

Comments
 (0)