Top

A03,CentOS 7.6.1810 安装Ansible,配置 Ansible,并测试

CentOS 浏览 评论


一、命令:yum install ansible 安装Ansible



二、命令:yum install vim 安装VIM



三、命令:ssh-keygen -t rsa 生成密钥,并将公钥复制到节点当中去,输入这个命令后,一直回车就行,如下图:

311559271569658163.png

之后命令:cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys 



四、命令:ssh-copy-id -i root@192.168.108.129 复制Ansible公钥到节点,会提示输入密码:

ssh-copy-id -i root@192.168.108.129

ssh-copy-id -i root@192.168.108.130



五、配置一个Ansible测试组,命令:vim /etc/ansible/hosts ,在里面加入如下内容:

[test-servers]

192.168.108.129

192.168.108.130



六、ping一下测试,命令:ansible test-servers -m ping,成功则输出如下内容:

192.168.108.130 | SUCCESS => {

    "changed": false,

    "ping": "pong"

}

192.168.108.129 | SUCCESS => {

    "changed": false,

    "ping": "pong"

}