[英]Ansible Dynamic Inventory with Openstack
我正在将多个Linux主机部署到开放堆栈环境,并尝试使用ansible配置它们。 我在https://github.com/ansible/ansible/blob/devel/contrib/inventory/openstack.py的库存动态库存脚本中遇到了一些困难
如果我用静态主机文件运行ansible,一切正常
# inventory/static-hosts
localhost ansible_connection=local
linweb01 ansible_host=10.1.1.101
% ansible linweb01 -m ping -i ./inventory/static-hosts \ --extra-vars="ansible_user=setup ansible_ssh_private_key_file=/home/ian/keys/setup.key" linweb01 | SUCCESS => { "changed": false, "ping": "pong" }
但是,如果我使用动态清单,则找不到主机
% ansible linweb01 -m ping -i ./inventory/openstack.py \
--extra-vars="ansible_user=setup ansible_ssh_private_key_file=/home/ian/keys/setup.key"
linweb01 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname linweb01: Name or service not known\r\n",
"unreachable": true
}
当我手动运行清单脚本时,找到了主机并且返回的地址正确
% ./inventory/openstack.py --host linweb01
[...]
"name": "linweb01",
"networks": {},
"os-extended-volumes:volumes_attached": [],
"power_state": 1,
"private_v4": "10.1.1.101",
[...]
我的猜测是,清单脚本不知道使用IP地址的“ private_v4”值,尽管我似乎找不到与此相关的参考。
如何使用清单脚本返回的“ private_v4”值作为主机的“ ansible_host”值?
快速查看代码表明该IP地址应该在interface_ip
密钥中:
hostvars[key] = dict(
ansible_ssh_host=server['interface_ip'],
ansible_host=server['interface_ip'],
openstack=server)
如果需要解决方法,可以尝试将其添加到group_vars/all.yml
:
ansible_host: "{{ private_v4 }}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.