Centos7安装ansible自动化运维工具

  • 2021年8月28日
  • DevOps

一、安装ansible软件
1、安装yum源

rpm -Uvh http://mirrors.ustc.edu.cn/epel/epel-release-latest-7.noarch.rpm
yum install epel-release -y
yum install ansible

要是报错:epel源与python版本冲突原因,有些包是需要依赖python2.6的版本,此主机的python版本是2.7.5。
2、那就先卸载 epel-release源

yum  install  epel-release  -y

3、到 /etc/yum.repos.d 目录下,将epel.repo源备份

mv  epel.repo  epel.repo.bak

4、清理yum源缓存和新建缓存

yum clean all
yum makecache

5、再执行安装命令

yum  install  ansible  -y

6、查看安装的版本

ansible --version

7、配置主机组
Ansible工具默认主目录为/etc/ansible/,其中hosts文件为被管理机IP或者主机名列


二、配置免秘钥登录
1、管理主机上生成秘钥

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
73:80:07:fa:9a:0d:e0:0e:d1:c2:44:d2:d2:61:67:21 root@ansible
The key's randomart image is:
+--[ RSA 2048]----+
|o=E.+..          |
|=oo+ . o         |
|ooo . . o        |
| + . . . .       |
|. . . . S .      |
| o   =   o       |
|  . o .          |
|                 |
|                 |
+-----------------+

2、将管理机上生成的秘钥发送到被管理机

ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.112.130
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.223.131

3、测试是否配置成功

ansible -k all -m ping

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注