1、ansible简介:
ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、
cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命
令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是
ansible所运行的模块,ansible只是提供一种框架。
主要包括:
(1)、连接插件connection plugins:负责和被监控端实现通信;
(2)、host inventory:指定操作的主机,是一个配置文件里面定义监控的主机;
(3)、各种模块核心模块、command模块、自定义模块;
(4)、借助于插件完成记录日志邮件等功能;
(5)、playbook:剧本执行多个任务时,非必需可以让节点一次性运行多个任务。
2 Ansible离线编译安装
(1)python2.7安装
准备编译环境
yum install zlib-devel bzip2-devel openssl-devel gcc python-devel
tar xvzf Python-2.7.8.tgz
cd Python-2.7.8
./configure --prefix=/usr/local/python2.7/
make && make install
备份旧版本的python,并符号链接新版本的python2.7
mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/bin/python2.7 /usr/bin/python
修改yum脚本,使其指向旧版本的python2.6,已避免yum无法运行
sed -i 's$#!/usr/bin/python$#!/usr/bin/python2.6$g' /usr/bin/yum
(2)setuptools模块安装
tar xvzf setuptools-7.0.tar.gz
cd setuptools-7.0
python setup.py install
(3)pycrypto模块安装
tar xvzf pycrypto-2.6.1.tar.gz
cd pycrypto-2.6.1
python setup.py install
(4)PyYAML模块安装
tar xvzf yaml-0.1.5.tar.gz
cd yaml-0.1.5
./configure --prefix=/usr/local
make && make install
tar xvzf PyYAML-3.11.tar.gz
cd PyYAML-3.11
python setup.py install
(5)Jinja2模块安装
tar xvzf MarkupSafe-0.9.3.tar.gz
cd MarkupSafe-0.9.3
python setup.py install
tar xvzf Jinja2-2.7.3.tar.gz
cd Jinja2-2.7.3
python setup.py install
(6)paramiko模块安装
tar xvzf ecdsa-0.11.tar.gz
cd ecdsa-0.11
python setup.py install
tar xvzf paramiko-1.15.1.tar.gz
cd paramiko-1.15.1
python setup.py install
(7)simplejson模块安装
tar xvzf simplejson-3.6.5.tar.gz
cd simplejson-3.6.5
python setup.py install
(8)ansible安装
tar xvzf ansible-1.7.2.tar.gz
cd ansible-1.7.2
python setup.py install
mkdir /etc/ansible
cp -r /root/ansible-1.7.2/examples/* /etc/ansible/
(9)测试是否安装成功
/usr/local/python2.7/bin/ansible-doc -l 显示内容如下图
acl Sets and retrieves file ACL information.
add_host add a host (and alternatively a group) to the ansible-playbo
airbrake_deployment Notify airbrake about app deployments
alternatives Manages alternative programs for common commands
apache2_module enables/disables a module of the Apache2 webserver
apt Manages apt-packages
apt_key Add or remove an apt key
apt_repository Add and remove APT repositories
apt_rpm apt_rpm package manager
arista_interface Manage physical Ethernet interfaces
arista_l2interface Manage layer 2 interfaces
arista_lag Manage port channel (lag) interfaces
arista_vlan Manage VLAN resources
assemble Assembles a configuration file from fragments
assert Fail with custom message