ansible

104 阅读1分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

Ansible

/etc/ansible/ansible.cfg

先配置/etc/ansible/ansible.cfg

[root@xnode1 ~]# vi /etc/ansible/ansible.cfg 
#line 71 取消注释
    71 host_key_checking = False

/etc/ansible/hosts

然后配置vi /etc/ansible/hosts

[root@xnode1 ~]# vi /etc/ansible/hosts 
#加入xnode2和xnode3以及ansible的用户和密码
[xnode]
xnode2
xnode3
[xnode:vars]
ansible_user=root
ansible_password="000000"

/etc/hosts

配置hosts文件 如果在/etc/ansible/hosts文件中写了主机名,那么就要在/etc/hosts中填写对应的hosts纪录

vi /etc/hosts 
192.168.200.11 xnode1
192.168.200.12 xnode2
192.168.200.13 xnode3

使用ping测试

[root@xnode1 ~]# ansible xnode -m ping
xnode2 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python""/usr/bin/python"
},
"changed"false,
"ping""pong"
}
xnode3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python""/usr/bin/python"
},
"changed"false,
"ping""pong"
}
[root@xnode1 ~]

使用copy模块来进行传送文件

[root@xnode1 ~]# ansible xnode -m copy -a "src=/etc/hosts dest=/etc/hosts" xnode2 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "checksum": "71195bb99cf97e1eb809604035d2abc3e8ea97ee", "dest": "/etc/hosts", "gid": 0, "group": "root", "md5sum": "7f0d53cb10128d82a1da1a9bd52adb77", "mode": "0644", "owner": "root", "secontext": "system_u:object_r:net_conf_t:s0", "size": 224, "src": "/root/.ansible/tmp/ansible-tmp-1640445760.37-2717-112739315780724/source", "state": "file", "uid": 0 } xnode3 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, "checksum": "71195bb99cf97e1eb809604035d2abc3e8ea97ee", "dest": "/etc/hosts", "gid": 0, "group": "root", "md5sum": "7f0d53cb10128d82a1da1a9bd52adb77", "mode": "0644", "owner": "root", "secontext": "system_u:object_r:net_conf_t:s0", "size": 224, "src": "/root/.ansible/tmp/ansible-tmp-1640445760.37-2719-63938142134339/source", "state": "file", "uid": 0 } [root@xnode1 ~]#