在 Ansible 2.1 中,我有一个角色被需要访问主机文件变量的剧本调用。关于如何访问它的任何想法?
我正在尝试访问以下库存文件部分ansible_ssh_host
中的 :test1
host
[test1]
test-1 ansible_ssh_host=abc.def.ghi.jkl ansible_ssh_port=1212
[test2]
test2-1 ansible_ssh_host=abc.def.ghi.mno ansible_ssh_port=1212
[test3]
test3-1 ansible_ssh_host=abc.def.ghi.pqr ansible_ssh_port=1212
test3-2 ansible_ssh_host=abc.def.ghi.stu ansible_ssh_port=1212
[all:children]
test1
test2
test3
我尝试通过以下方式访问该角色:
{{ hostvars.ansible_ssh_host }}
和
{{ hostvars.test1.ansible_ssh_host }}
我收到此错误:
fatal: [localhost]: FAILED! => {"failed": true, "msg": "'ansible.vars.hostvars.HostVars object' has no attribute 'ansible'"}