自动化运维(ansible)

发布时间:2026/6/23 23:58:12
自动化运维(ansible) 自动化运维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.25192.168.1.26[group02]192.168.1.25192.168.1.26192.168.1.27测试连接性[root@mo ~]# ansible 192.168.1.25 -m ping192.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.25192.168.1.26other ansible_ssh_host=192.168.1.27 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=1[group02]192.168.1.25192.168.1.26other再次测试连通性group01:[root@mo ~]# ansible group01 -m ping192.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": "pong"}other | SUCCESS = {