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:
---
- name: Deploy Test VM
hosts: localhost
tags:
- deploy
roles:
- { role: deploy_azurevm, vm_name: "{{ resource_group_prefix
}}-trondtest", add_to_adhoc_group: "{{ resource_group_name }}" }
Since it works on the Windows "version" of "Add vm to inventory" everything
should be fine, no?
I'm baffled. Any pointers appreciated!
_Trond
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/738cf636-65cb-4a3d-924d-5797988cf30c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.