Ansible

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 ~]# 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cc_pwd

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值