简体   繁体   中英

How to get hosts variables with Ansible?

Ansible: v2.3.0.0
Python: v2.7.12


The hosts file:

[server1]
192.168.0.1

At playbook, tried this way to get the IP value:

- debug:
    msg: "Host: {{ hostvars['server1'] }}"

It said hostvars.HostVars has no attribute server1 .

server1 is a group name in your example. If you want server1 to be a host, define inventory like this:

[myservers]
server1 ansible_host=192.168.0.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM