A-Ansible安装及配置

时间:2023-02-23 11:53:44

安装环境

编译安装环境 Linux(centos 7.6) Ansible(1.5.12

主机信息:

部署规划:

172.24.77.241(​​sr1.dj.com​​):运行Ansilble

172.24.77.242(​​sr2.dj.com​​):客户机

YUM安装ansible

yum install epel-release -y
yum install ansible -y

编译安装:

yum -y install python-jinja2 PyYAML python-paramiko python-babel
python-crypto
tar xf ansible-1.5.4.tar.gz
cd ansible-1.5.4
python setup.py build
python setup.py install
mkdir /etc/ansible
cp -r examples/* /etc/ansible

Git方式:

git clone git://github.com/ansible/ansible.git --recursive
cd ./ansible
source ./hacking/env-setup

pip安装: pip是安装Python包的管理器,类似yum

yum install python-pip python-devel
yum install gcc glibc-devel zibl-devel rpm-bulid openssl-devel
pip install --upgrade pip
pip install ansible --upgrade

ll /etc/ansible/
-rw-r--r-- 1 root root 19985 Jun 19 11:04 ansible.cfg ###主配置文件
-rw-r--r-- 1 root root 1016 Jun 19 11:04 hosts ###文件为被管理机IP或者主机名列表,可以配置分组,定义各种IP及规则
drwxr-xr-x 2 root root 6 Jun 19 11:04 roles ###为角色或者插件路径,默认目录为空

配置ansible

vim /etc/ansible/hosts
[admin]
172.24.77.241
[web]
172.24.77.242
[db]
172.24.77.243
vim /etc/ansible/ansible.cfg

host_key_checking = False

查看Ansible支持的模块

ansible-doc -l|more
ansible-doc ping