准备
- 服务器安装python
- 服务器安装epel源
安装ansible需要用epel源,故需要安装
[root@liuqin yum.repos.d]# yum list | grep epel-release
epel-release.noarch 7-12 epel
[root@liuqin yum.repos.d]# yum install -y epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-12 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================================
Installing:
epel-release noarch 7-12 epel 15 k
Transaction Summary
===========================================================================================================================================================================
Install 1 Package
Total download size: 15 k
Installed size: 24 k
Downloading packages:
epel-release-7-12.noarch.rpm | 15 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-12.noarch 1/1
warning: /etc/yum.repos.d/epel.repo created as /etc/yum.repos.d/epel.repo.rpmnew
Verifying : epel-release-7-12.noarch 1/1
Installed:
epel-release.noarch 0:7-12
Complete!
在/etc/yum.repos.d下可看到增加了epel源
安装
yum -y install ansible
查看是否安装成功:
image.png
基本配置
主要配置文件有两个:
- /etc/ansible/ansible.cfg
ansible.cfg是基本配置文件,可用默认的,修改以下几个配置:
log_path = /var/log/ansible.log
hostfile = /home/ansible/hosts
host_key_checking = False
- /etc/ansible/hosts
hosts为节点管理文件,主要配置需要ansible远程操作的服务器,hosts文件配置类似如下格式:
[portal]
IP ansible_ssh_user=user_name ansible_ssh_pass=user_passwd
PS:特别要注意一下hosts文件为严格的yaml格式,格式稍有差池就无法正常使用












网友评论