I am looking at extracting the value of Ansible host from hostvars, however I am not just getting the value.
the purpose is to select a random host from a group and use the name and IP to create a VM instance on proxmox as a sudo load balanced way of creating VMs.
Here is my playbook:
---
- hosts: localhost
become: yes
vars:
- testvar: "{{ groups['proxmox_hypervisor'] | random }}"
- anothertest: "hostvars.{{ testvar }}.ansible_host"
tasks:
- name: Print Host IP Address
ansible.builtin.debug:
var: "{{ anothertest }}"
I'm getting
TASK [Print Host IP Address] ******************************************
task path: /home/ansible/ceh-ansible/test.yml:8
ok: [localhost] => {
"hostvars.b550.ansible_host": "192.168.5.178"
}
but I'm expecting
TASK [Print Host IP Address] *******************************************
task path: /home/ansible/ceh-ansible/test.yml:8
ok: [localhost] => {
"192.168.5.178"
}
What am I doing wrong?