linux

centos7中ansible安装

我在192.168.0.203上安装了ansible,用于远程操控远程主机

在192.168.0.203  上的操作如下

首先配置yum源为阿里源

cd /etc/yum.repos.d/
#备份原来的源
mv CentOS-Base.repo CentOS-Base.repo.bak
#下载阿里的centos7源
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

安装epel源(安装ansible等一些软件需要epel源)

介绍

EPEL(Extra Packages for Enterprise Linux)是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS等提供高质量软件包的项目。装上了 EPEL,就像在 Fedora 上一样,可以通过 yum install 软件包名,即可安装很多以前需要编译安装的软件、常用的软件或一些比较流行的软件,比如现在流行的nginx、htop、ncdu、vnstat等等,都可以使用EPEL很方便的安装更新。

  简单来说,就是EPEL中的软件是经过测试的,兼容性和质量是敢打包票的。如果是生产环境的服务器一定要配置,个人用于学习的话可以不用配置。但是推荐安装。

操作

yum install -y epel-release
或使用阿里epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

安装ansible

yum install -y ansible

安装后,可看到如下内容

[root@MES-203 ansible]# pwd
/etc/ansible
[root@MES-203 ansible]# ll
总用量 24
-rw-r--r--. 1 root root 19984 10月 20 10:18 ansible.cfg
-rw-r--r--. 1 root root  1214 10月 20 10:14 hosts
drwxr-xr-x. 2 root root     6 1月  16 2022 roles
[root@MES-203 ansible]# 

配置下不检查host_key

把/etc/ansible/ansible.cfg中的如下内容取消注释
# uncomment this to disable SSH key host checking
host_key_checking = False

因为我在操作的时候,报了如下错

接下来就可以把想远程操控的主机放到hosts文件中了

[root@MES-203 ansible]# pwd
/etc/ansible
[root@MES-203 ansible]# cat hosts 
[etcd]
192.168.0.203 ansible_ssh_user=root ansible_ssh_pass=adm
192.168.0.204 ansible_ssh_user=root ansible_ssh_pass=adm
192.168.0.205 ansible_ssh_user=root ansible_ssh_pass=adm
[root@MES-203 ansible]# 

测试一下是否有问题

[root@MES-203 ansible]# ansible etcd -m shell -a "cd /opt;ls -l"
192.168.0.205 | CHANGED | rc=0 >>
总用量 0
192.168.0.204 | CHANGED | rc=0 >>
总用量 0
192.168.0.203 | CHANGED | rc=0 >>
总用量 0

留言

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

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。
转载请注明来源:centos7中ansible安装 - 多知在线