[英]Ansible: ansible_domain or facter_domain - How to get domain value of a hostname mentioned in inventory file
Ansible 1.9.2 / 1.9.4
CentOS 6.7
在我的invetory文件中,我有:
[zabbix_server]
zabbix.dev-white.projectname.jenkins
[some_other_zabbix_server]
someotherzabbix.dev-blue.project.jenkins ansible_ssh_host=10.120.133.11
当我跑:
ansible -m setup -i hosts zabbix.dev-white.projectname.jenkins
它给了我以下错误:
zabbix.dev-white.projectname.jenkins | FAILED => FAILED:没有可用的身份验证方法
在我的剧本中,我正在尝试获取zabbix服务器的域值,即dev-white.projectname.jenkins。 我尝试了以下但是用于显示域值的变量是空白/ null,为什么?
注意: inventory_hostname的值正确显示!! 但是ansible_domain / facter_domain的域值将作为空/空值。
- debug: msg="My server is= {{ hostvars[groups['zabbix_server'][0]].inventory_hostname }} and domain is= {{ hostvars[groups['zabbix_server'][0]].ansible_domain }} --- {{ hostvars[groups['zabbix_server'][0]]['inventory_hostname'] }} -- {{ hostvars[groups['zabbix_server'][0]]['ansible_domain'] }} -- -- {{ hostvars[groups['zabbix_server'][0]]['facter_domain'] }}"
尝试使用some_other_zabbix_server组变量的上述代码(其中设置了ansible_ssh_host变量),仍然没有显示其域的值。 PS: ansible_ssh_host属性将在较新的Ansible版本中弃用 。
一种方法是拆分和连接除第一部分之外的所有部分。
- debug: var="{{ groups['zabbix_server'][0].split('.')[1:] | join('.') }}"
结果:
"dev-white.projectname.jenkins"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.