一、简介
Ansible is a radically simple configuration-management, application deployment, task-execution, and multinode orchestration engine.
Design Principles
Have a dead simple setup process and a minimal learning curve
Be super fast & parallel by default
Require no server or client daemons; use existing SSHd
Use a language that is both machine and human friendly
Focus on security and easy auditability/review/rewriting of content
Manage remote machines instantly, without bootstrapping
Allow module development in any dynamic language, not just Python
Be usable as non-root
Be the easiest IT automation system to use, ever.
二、安装
ansible依赖于Python 2.6或更高的版本、paramiko、PyYAML及Jinja2。
2.1 编译安装
解决依赖关系
# 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
2.2 rpm包安装
# yum install ansible
注意:不同版本的ansible的功能差异可能较大。
三、简单应用
ansible通过ssh实现配置管理、应用部署、任务执行等功能,因此,需要事先配置ansible端能基于密钥认证的方式联系各被管理节点。
ansible <host-pattern> [-f forks] [-m module_name] [-a args]
-m module:默认为command
ansible-doc: Show Ansible module documentation
-l, --list List available modules
-s, --snippet Show playbook snippet for specified module(s)
实例应用:
ssh-keygen -t rsa -P ''
ssh-copy-id -i .ssh/id_rsa.pub root@103.242.135.25
一、定义host
使用yum模块,批量安转tree工具包
ansible all -m yum -a "name=tree state=installed"
name:指定安装包名
state:指定方式,安装或卸载
安装: install (`present' or `installed', `latest'),
卸载:remove (`absent' or `removed') a package
ansible all -m yum -a "name=httpd* state=latest" #安装httpd服务
service模块使用,关闭服务:stopped 开启服务:started