自动化运维
ansible----自动化运维工具
特点:
部署简单,使用ssh管理
管理端与被管理端不需要启动服务
配置简单、功能强大,扩展性强
一、ansible环境搭建
准备四台机器
安装步骤
mo服务器:
#下载epel
[root@mo ~]# yum -y install epel-release.noarch
#安装ansible
[root@mo ~]# yum -y install ansible
#查看ansible版本
[root@mo ~]# ansible --version
进行免密登录
[root@mo ~]# ssh-copy-id -i 192.168.1.25
[root@mo ~]# ssh-copy-id -i 192.168.1.26
编辑配置文件
[root@mo ~]# vim /etc/ansible/hosts
[group01]
192.168.1.25
192.168.1.26
[group02]
192.168.1.25
192.168.1.26
192.168.1.27
测试连接性
[root@mo ~]# ansible 192.168.1.25 -m ping
192.168.1.25 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
设置别名分组
[root@mo ~]# vim /etc/ansible/hosts
[group01]
192.168.1.25
192.168.1.26
other ansible_ssh_host=192.168.1.27 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=1
[group02]
192.168.1.25
192.168.1.26
other
再次测试连通性
group01:
[root@mo ~]# ansible group01 -m ping
192.168.1.26 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.1.25 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping&#