帶登入憑據的動態庫存
將動態庫存傳遞給 ansible-playbook
:
ansible-playbook -i inventory/dyn.py -l targethost my_playbook.yml
python inventory/dyn.py
應該列印出這樣的東西:
{
"_meta": {
"hostvars": {
"10.1.0.10": {
"ansible_user": "vagrant",
"ansible_ssh_private_key_file": "/home/mrtuovinen/.ssh/id_rsa",
"ansible_port": 22
},
"10.1.0.11": {
"ansible_user": "ubuntu",
"ansible_ssh_private_key_file": "/home/mrtuovinen/.ssh/id_rsa",
"ansible_port": 22
},
"10.1.0.12": {
"ansible_user": "steve",
"ansible_ssh_private_key_file": "/home/mrtuovinen/.ssh/key.pem",
"ansible_port": 2222
}
}
},
"vagrantbox": [
"10.1.0.10"
],
"ubuntubox": [
"10.1.0.11"
],
"osxbox": [
"10.1.0.12"
]
}