需要准备控制机和被控机,在控制机上安装ansible,被控机能ping通
1.安装ansible
2.mkdir -p /root/ansible/roles
3.vim /root/ansible/inventory
inventory内容:
[root] #主机名称
172.30.201.207 #被控机名称
[all:vars] #所有参数
ansible_user=root #被控机用户名
ansible_password=Qwer!234 #被控机密码
4.cp -vp /etc/ansible/ansible.cfg /root/ansible/ansible.cfg
5.vim /root/ansible/ansible.cfg
#总共只修改四行
inventory = /root/ansible/inventory
roles_path = /root/ansible/roles
host_key_checking = False
remote_user = root
6.ansible --version
7.ansible-inventory --graph
结果
1.cd /root/ansible
2.ansible all -m hostname -a name=dyb
预期结果
[root@ans-01 ansible]# ansible all -m hostname -a name=dyb
[WARNING]: Unable to parse /root/ansible/roles as an inventory source
[WARNING]: Platform linux on host 172.30.201.207 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
172.30.201.207 | CHANGED => {
"ansible_facts": {
"ansible_domain": "",
"ansible_fqdn": "dyb",
"ansible_hostname": "dyb",
"ansible_nodename": "dyb",
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"name": "dyb"
}