Accessing inventory host variable in Ansible playbook

前端 未结 6 1853
夕颜
夕颜 2020-12-03 00:52

I am using Ansible 2.1. I have the following inventory host file and a role being called by a play that needs access to the host file variable. Any thoughts on how to acce

6条回答
  •  青春惊慌失措
    2020-12-03 00:55

    [host_group]
    host-1 ansible_ssh_host=192.168.0.21 node_name=foo
    host-2 ansible_ssh_host=192.168.0.22 node_name=bar
    
    [host_group:vars]
    custom_var=asdasdasd
    

    You can access host group vars using:

    {{ hostvars['host_group'].custom_var }}
    

    If you need a specific value from specific host, you can use:

    {{ hostvars[groups['host_group'][0]].node_name }}
    

提交回复
热议问题