Proxmox的Ansible动态库存
时间:2020-03-21 11:42:39 来源:igfitidea点击:
安装
在Ansible控制节点上,切换到存储剧本的文件夹:
$cd /home/ansible/playbooks
从https://github.com/xezpeleta/Ansible-Proxmox-inventory下载脚本。
$git clone https://github.com/xezpeleta/Ansible-Proxmox-inventory.git
使它可执行:
$chmod 0755 ./proxmox.py
配置
尝试列出动态AD资源:
$./proxmox.py \
--url=https://pve.theitroad.com:8006/\
Hyman@theitroad \
--password=changeme \
--list --pretty
{
"all": {
"hosts": [
"ansible5.hl.local",
"proxy1.hl.local",
"ansible2.hl.local",
"rhel70-tmpl",
"monitoring.hl.local",
"storage1.hl.local",
"admin2.hl.local",
"katello.hl.local",
"db1.hl.local",
"web2.hl.local",
"proxy2.hl.local",
"ansible3.hl.local",
"db2.hl.local",
"ldap2.hl.local",
"syslog.hl.local",
"admin1.hl.local",
"web1.hl.local",
"ansible4.hl.local",
"ldap1.hl.local",
"ansible1.hl.local",
"backup.hl.local",
"storage2.hl.local"
]
},
[...]
使用环境变量创建文件“ setenv.sh”以存储Proxmox凭据:
#!/bin/bash export PROXMOX_URL=https://pve.theitroad.com:8006/ export Hyman@theitroad export PROXMOX_PASSWORD=changeme
在当前Shell环境中从filename执行命令:
$source ./setenv.sh
列出动态列表,而不在CLI上传递凭据:
$./proxmox.py --list --pretty
与Ansible一起使用AD资源:
$ansible all -i ./proxmox.py -m ping -u ansible
ansible5.hl.local | SUCCESS => {
"changed": false,
"ping": "pong"
}
proxy1.hl.local | SUCCESS => {
"changed": false,
"ping": "pong"
}
[...]

