Hi all,
I have this weird thing inside a role, hopefully someone can straighten me out:
My role is a custom made one, which performs Azure vm deployments, supporting both Linux and Windows. The last steps of the role are as follows:
-
name: debug
debug:
msg: “os_type: {{ os_type }} add_to_inventory: {{ add_to_inventory }}” -
name: Add vm to inventory (Windows)
when: os_type == “Windows”
add_host:
ansible_host: “{{ vm_mgmt_ip }}”
name: “{{ vm_name }}”
groups: “{{ add_to_adhoc_group }}”
ansible_user: “{{ admin_username }}”
ansible_password: “{{ admin_password }}”
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore -
name: Add vm to inventory (Linux)
when: os_type == “Linux” and add_to_adhoc_group is defined
add_host:
ansible_host: “{{ vm_mgmt_ip }}”
name: “{{ vm_name }}”
groups: “{{ add_to_adhoc_group }}”
ansible_user: “{{ admin_username }}”
ansible_ssh_pass: “{{ admin_password }}”
ansible_become: yes
My problem is that regardless of the OS, Ansible will execute the “linux” task, here is the output from a run deploying a Windows VM:
TASK [deploy_azurevm : debug] *******************************************
ok: [localhost] => {
“msg”: “os_type: Windows add_to_inventory: internal_ip”
}
TASK [deploy_azurevm : Add vm to inventory (Windows)] *******************
changed: [localhost]
TASK [deploy_azurevm : Add vm to inventory (Linux)] *********************
ERROR! ‘resource_group_name’ is undefined
This used to work, but as I’m constantly updating both the role and the Ansible version I’m unable to track down exactly what changed. Has anyone seen something similar?
Also, the fact that “resource_group_name” is undefined also seems strange to me, the role task shouldn’t care about that variable at all. The only reference to it is how I pass in vars to the role: