上节内容回顾加实践
41是管理机:
41----->61
41----->31
![](https://img.haomeiwen.com/i16833235/f8e5d5e366f7451a.png)
1)在41上配置ansible
!/bin/bash
yum install ansible -y
ssh-keygen -f ~/.ssh/id_rsa -P '' -q
for ip in 31 61
do
sshpass -p123456 ssh-copy-id -f -i ~/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no" 172.16.1.$ip
done
test
ssh 172.16.1.61 "ifconfig eth0"
ssh 172.16.1.31 "ifconfig eth0"
2)ansible基本配置
[root@backup ~]# cat /etc/ansible/hosts
[oldboy]
172.16.1.31
172.16.1.61
vim /etc/ansible/ansible.cfg +374
结尾增加: -o StrictHostKeyChecking=no
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no
3)使用ansible
[root@backup ~]# ansible oldboy -m command -a "free -m"
172.16.1.31 | CHANGED | rc=0 >>
total used free shared buff/cache available
Mem: 972 79 791 7 101 757
Swap: 767 0 767
172.16.1.61 | CHANGED | rc=0 >>
total used free shared buff/cache available
Mem: 972 66 768 7 137 754
Swap: 767 0 767
4)查看使用帮助
ansible-doc -l #模块就Linux命令了。
command Executes a command on a remote node
查模块的参数:
ansible-doc -s command #Linux命令参数
网友评论