ansible
一.安装
1.配置yum源
每台机器上操作
#vim /etc/yum.repos.d/yum.repo
[ansible]
name=ansible
baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/7/x86_64/
gpgcheck=0
安装(每台机器)
yum install ansible -y
2.设置免密登录
ssh-keygen
ssh-copy-id server1
ssh-copy-id server2
3.修改master的hosts文件
cat /etc/ansible/hosts
[test]
172.25.65.11
172.25.65.12
[my]
172.25.65.10
测试
[root@server10 ansible]# ansible test -m ping
server11 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
二.远程执行命令
https://www.cnblogs.com/amber-liu/p/10403512.html
[root@localhost ~]$ ansible 192.168.119.134 -m command -a 'date' # 对指定的主机远程执行命令,-m 指定使用哪个模块,-a 指定执行哪些命令
[root@localhost ~]$ ansible test -m command -a 'date' # 对指定的主机组远程执行命令,需要先配置/etc/ansible/hosts
[root@localhost ~]$ ansible 192.168.119.134 -m shell -a 'ls | grep txt' # 如果要执行的命令带有管道,必须使用 shell 模块