免责声明:我刚接触ansible,找不到here、here或here的答案。
我需要对2台主机运行一本攻略。我知道如何使用yaml或INI格式的静态清单来实现这一点,但是当我尝试使用动态清单时--具体地说,就是VMWare dynamic inventory - vmware_inventory.py 。运行动态库存的结果如下所示:
{
"_meta": {
"hostvars": {
"foo_420be125-0a38-6dcd-247c-1d1839717804": {
"ansible_connection": "ssh",
"ansible_user": "root",
"config.cpuHotAddEnabled": false,
"config.cpuHotRemoveEnabled": false,
"config.hardware.numCPU": 4,
"config.instanceUuid": "500b86dc-b51e-25fb-165d-e51c62ecd725",
"config.name": "foo",
"config.template": false,
"guest.guestId": null,
"guest.guestState": "notRunning",
"guest.hostName": "foo.bar.com",
"guest.ipAddress": "1.2.3.4",
"name": "foo",
"runtime.maxMemoryUsage": null,
"stage": "dev"
},
"bar_fffe-6f29-3e32-0ce9a80d0ad3": {
"ansible_connection": "ssh",
...
}
},
"activedirectory-devops": {
"hosts": [
"foo_420be125-0a38-6dcd-247c-1d1839717804",
"bar_fffe-6f29-3e32-0ce9a80d0ad3"
]
},
"all": {
"children": [
"activedirectory-devops",
"centos64Guest",
"centos7_64Guest",
"com.vmware.vr.HasVrDisks",
"other3xLinux64Guest",
"otherGuest",
...注意:activedirectory-devops是VMWare vCenter中的一个“标记”,它(显然)是作为一个可分析的“主机组”返回的。
鉴于此,我如何针对activedirectory-devops中的主机运行攻略?毕竟,DNS不能解析"foo_420be125-0a38-6dcd-247c-1d1839717804“。
我最好的猜测是:
ansible-playbook -i vmware.yml site.yml发布于 2019-10-31 08:56:52
我刚刚解决了我自己的问题,如下所示:
ansible activedirectory-devops -m ping --connection=local -i vmware.yml结果:
foo_420be125-0a38-6dcd-247c-1d1839717804 | SUCCESS => {
"changed": false,
"ping": "pong"
}
bar_fffe-6f29-3e32-0ce9a80d0ad3 | SUCCESS => {
"changed": false,
"ping": "pong"
}发布于 2019-10-31 04:30:19
不确定您绑定的是哪个动态清单文件..
您可以尝试在动态库存.ini文件中使用"skip_keys“删除不需要的属性。(取消注释ini文件中的skip_keys并指定不需要的属性)
对于使用动态库存的攻略:
ANSIBLE_HOSTS variable to always use the VMWare inventory:
export ANSIBLE_HOSTS="/home/blabla/vmware-ansible/query.py"
Or using playbook:
ansible-playbook example.yml -i inventory其中清单目录包含...
inventory/
01-openstack.yml # configure inventory plugin to get hosts from Openstack cloud
02-dynamic-inventory.py # add additional hosts with dynamic inventory script
03-static-inventory # add static hosts
group_vars/
all.yml # assign variables to all hostshttps://stackoverflow.com/questions/58628238
复制相似问题