一、ansibles配置与测试
1、ansible的安装配置
利用公钥批量管理
[[email protected] ~]# ssh-keygen -t rsa #创建公钥 [[email protected] ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]192.168.11.206 #将公钥拷贝到管理主机中.ssh/authorized_keys文件中,实现免密码登录远程管理主机 [[email protected] ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]192.168.11.207 #将公钥拷贝到管理主机中.ssh/authorized_keys文件中,实现免密码登录远程管理主机 注: 如果在生成密钥的时候设置了密码,ansible每次执行命令的时候,都会提示输入密钥密码,可通过下面的命令记住密码。 ssh-agent bsh ssh-add ~/.ssh/id_rsa
2、控制端安装ansible程序
在线安装:
[[email protected] ~]# yum install epel-release -y [[email protected] ~]# yum install ansible -y
离线安装:
[[email protected] ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [[email protected] ~]# yum install ansible -y
3、配置ansible
[[email protected] ~]# vim /etc/ansible/hosts [web01] #客户端主机名 192.168.11.206 #客户端IP地址 [web02] 192.168.11.207 [web:children] web01 web02
4、验证ansible,通过ssh端口探测通信
[[email protected] ~]# ansible web -m ping #能正常ping通客户端所有主机 192.168.11.206 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } 192.168.11.207 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" }
5、测试
[[email protected] ~]# ansible web --list-hosts #查看所有连接主机正常 hosts (2): 192.168.11.206 192.168.11.207
二、ansible命令语法格式及模块
原文地址:https://www.cnblogs.com/comprehensive/p/12160693.html
时间: 2024-10-29 22:28:53