Hello,
I am trying to use hostvars to get an inventory hostname and a specific
variable. The goal of this is to get from the app group, get each unique
servers client_name. The below command works for just the first line as I
am fairly confident the 0 means first item in the inventory file.
I need to get it to be a per line item of the inventory file so that each
servers client name is read out. I have tried a couple variations but I
can't seem to get this correct. Can anyone provide any insight as to what I
might be doing wrong.
"{{ hostvars[groups['apps'][0]]['client_name'] }}"
inventory file
[apps]
server1 instance_user=fondinst client_name=fondprd1 server_ip=
server2 instance_user=kumcinst client_name=kumcprd1 `server_ip=
[proxy]
proxy1
Playbook
* hosts: 127.0.0.1
connection: local
gather_facts: no
* hosts: app
tasks:
* name: debug
debug: msg={{ client_name }}
* hosts: proxy
tasks:
* name: debug
debug: msg="{{ hostvars[groups['apps'][0]]['client_name'] }}"
Summary
Correct syntax for hostvars calling from a certain group, for an
inventory_hostname name, getting a variable
Linux Rhel6
Ansible version 2.4.4.4
component name:
Ansible
--
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/0e66f1e6-905d-471b-a5fd-48a535838987%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.