ansible-主机清单
1.ansible清单-默认
默认位置
/etc/ansible/hosts
查看主机清单文件
[root@localhost ansible]# cat hosts [webservers] 192.168.235.152 [outlocatservers] 43.143.98.52 [localhost] 127.0.0.1
[webservers],[outlocatservers],[localhost] 是主机名
2.ansible主机清单-自定义
调用方式:
ansible all/主机名 -i 主机清单文件路径 -m 模块 -a 模块参数
[root@localhost ansible]# ansible all -i /etc/ansible/hosts_bak2 -m ping 192.168.235.152 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } 127.0.0.1 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } 43.143.98.52 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } [root@localhost ansible]# ansible webservers -i /etc/ansible/hosts_bak2 -m ping 192.168.235.152 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } 43.143.98.52 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" }
ansible-playbook -i 主机清单文件路径 playbook.yml
[root@localhost logic]# ansible-playbook -i /etc/ansible/hosts_bak2 whwen_ansible.yml PLAY [webservers] ************************************************************************************************ TASK [Gathering Facts] ********************************************************************************************* ok: [43.143.98.52] ok: [192.168.235.152] TASK [test] ******************************************************************************************************** ok: [192.168.235.152] => { "msg": "测试" } ok: [43.143.98.52] => { "msg": "测试" } PLAY RECAP ******************************************************************************************************** 192.168.235.152 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 43.143.98.52 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0