Ansible:如何从动态资源清册中的标记获取主机
免责声明:我是ansible新手,无法找到答案,或者 我需要和两位主持人做一个剧本。我知道如何使用yaml或INI格式的静态清单来实现这一点,但我在尝试使用动态清单时迷失了方向。 运行动态资源清册的结果如下所示:Ansible:如何从动态资源清册中的标记获取主机,ansible,ansible-inventory,Ansible,Ansible Inventory,免责声明:我是ansible新手,无法找到答案,或者 我需要和两位主持人做一个剧本。我知道如何使用yaml或INI格式的静态清单来实现这一点,但我在尝试使用动态清单时迷失了方向。 运行动态资源清册的结果如下所示: { "_meta": { "hostvars": { "foo_420be125-0a38-6dcd-247c-1d1839717804": { "ansible_connection": "ssh",
{
"_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中的一个标记,显然是作为ansible主机组返回的
鉴于此,如何在activedirectory devops中针对主机运行playbook?毕竟,foo_420be125-0a38-6dcd-247c-1d1839717804无法通过DNS解析
我最好的猜测是:
ansible playbook-i vmware.yml site.yml
不确定要绑定的动态库存文件 您可以尝试在dynamic inventory.ini文件中跳过_键以删除不需要的属性。取消注释跳过ini文件中的键并指定不需要的属性 对于使用动态资源清册的游戏手册:
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 hosts
不确定要绑定的动态库存文件 您可以尝试在dynamic inventory.ini文件中跳过_键以删除不需要的属性。取消注释跳过ini文件中的键并指定不需要的属性 对于使用动态资源清册的游戏手册:
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 hosts
我刚刚解决了我自己的问题如下:
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"
}
我刚刚解决了我自己的问题如下:
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"
}
谢谢你。我更新了问题中的URL以显示我正在使用的确切脚本。我对你的回答投了赞成票,因为它给了我一些好主意,但实际的解决方案很简单:提到我需要的主机作为ansible的第一个参数:按照通常的语法:ansible[-f forks][m module_name][a args]谢谢。我更新了问题中的URL以显示我正在使用的确切脚本。我对您的回答投了赞成票,因为它给了我一些好主意,但实际的解决方案很简单:提到我需要的主机作为ansible的第一个参数:按照通常的语法:ansible[-f forks][m module_name][a args]