0.Ansible介紹html
Ansible 是一個簡單的自動化運維管理工具,能夠用來自動化部署應用、配置、編排 task(持續交付、無宕機更新等),採用 paramiko 協議庫(fabric 也使用這個)。python
特殊說明:本教程是CentOS6.6的安裝教程,在Linux 7的鏡像裏面通常都會帶ansible這個rpm包,經過 yum -y install ansible就能夠直接安裝。避免以下複雜的步驟。linux
1.安裝環境及介質nginx
安裝版本:Ansible 1.7.2git
操做系統:Linux localhost.localdomain 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linugithub
虛擬機鏡像:CentOS-6.6-x86_64-bin-DVD1.isojson
系統配置:1C(core)/1G(mem)/8G(disk)vim
介質:運維
ansible-1.7.2.tar.gz dom
https://github.com/ansible/ansible/archive/v1.7.2.tar.gz
ecdsa-0.11.tar.gz
https://pypi.python.org/packages/source/e/ecdsa/ecdsa-0.11.tar.gz
Jinja2-2.7.3.tar.gz
https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.3.tar.gz
MarkupSafe-0.9.3.tar.gz
https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.9.3.tar.gz
paramiko-1.15.1.tar.gz
https://pypi.python.org/packages/source/p/paramiko/paramiko-1.15.1.tar.gz
pycrypto-2.6.1.tar.gz
https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.1.tar.gz
Python-2.7.8.tgz
https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
PyYAML-3.11.tar.gz
https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.11.tar.gz
setuptools-7.0.tar.gz
https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz
simplejson-3.6.5.tar.gz
https://pypi.python.org/packages/source/s/simplejson/simplejson-3.6.5.tar.gz
yaml-0.1.5.tar.gz
http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz
2.開始安裝
2.1 Python2.7安裝
$ tar –zxvf Python-2.7.8.tgz
$ cd Python-2.7.8
$ ./configure –prefix=/usr/local
$ make --jobs=`grep processor /proc/cpuinfo | wc -l`
$ make install
## 將python頭文件拷貝到標準目錄,以免編譯ansible時,找不到所需的頭文件
$ cd /usr/local/include/python2.7
$ cp -a ./* /usr/local/include/
## 備份舊版本的python,並符號連接新版本的python
$ cd /usr/bin
$ mv python python2.6
$ ln -s /usr/local/bin/python
## 修改yum腳本,使其指向舊版本的python,已避免其沒法運行
$ vim /usr/bin/yum
# !/usr/bin/python --> #!/usr/bin/python2.6 (將Python改爲Python2.6)
2.2 python-setuptools模塊安裝
$ tar -zxvf setuptools-7.0.tar.gz
$ cd setuptools-7.0
$ python setup.py install
2.3 python-pycrypto模塊安裝
$ tar -zxvf pycrypto-2.6.1.tar.gz
$ cd pycrypto-2.6.1
$ python setup.py install
2.4 python-PyYAML模塊安裝
$ tar -zxvf yaml-0.1.5.tar.gz
$ cd yaml-0.1.5
$ ./configure --prefix=/usr/local
$ make --jobs=`grep processor /proc/cpuinfo | wc -l`
$ make install
$ tar -zxvf PyYAML-3.11.tar.gz
$ cd PyYAML-3.11
$ python setup.py install
2.5 python-Jinja2模塊安裝
$ tar -zxvf MarkupSafe-0.9.3.tar.gz
$ cd MarkupSafe-0.9.3
$ python setup.py install
$ tar -zxvf Jinja2-2.7.3.tar.gz
$ cd Jinja2-2.7.3
$ python setup.py install
2.6 python-paramiko模塊安裝
$ tar -zxvf ecdsa-0.11.tar.gz
$ cd ecdsa-0.11
$ python setup.py install
$ tar -zxvf paramiko-1.15.1.tar.gz
$ cd paramiko-1.15.1
$ python setup.py install
2.7 python-simplejson模塊安裝
$ tar -zxvf simplejson-3.6.5.tar.gz
$ cd simplejson-3.6.5
$ python setup.py install
2.8 python-ansible模塊安裝
$ tar -zxvf ansible-1.7.2.tar.gz
$ cd ansible-1.7.2
$ python setup.py install
3.配置及測試
3.1 配置
# SSH免密鑰登陸設置
$ ssh-keygen -t rsa -P ''
#遠程機器複製生成id_rsa.pub公鑰實現免密登陸,參考《Linux下實現免密登陸》
# ansible配置
$ mkdir -p /etc/ansible
$ touch /etc/ansible/ansible.cfg
$ vim /etc/ansible/ansible.cfg
粘貼以下內容:
[defaults]
inventory = /etc/ansible/hosts
sudo_user=root
remote_port=22
host_key_checking=False
remote_user=root
log_path=/var/log/ansible.log
module_name=command
private_key_file=/root/.ssh/id_rsa
no_log:True
$ touch /etc/ansible/hosts
$ vim /etc/ansible/hosts
粘貼以下內容:
[test]
192.168.91.137
3.2 測試
$ ansible test -m ping
4 . 參考文章
Ansible官網全模塊文檔
http://docs.ansible.com/ansible/list_of_all_modules.html
自動化運維工具Ansible詳細部署
http://sofar.blog.51cto.com/353572/1579894/
ansible快速上手
https://linuxtoy.org/archives/hands-on-with-ansible.html
Ansible:自動化工具
http://rangochen.blog.51cto.com/2445286/1425276
自動化工具ansible中文指南
http://www.aikaiyuan.com/6299.html
運維自動化之ansibleplaybook安裝nginx
http://dl528888.blog.51cto.com/2382721/1438847
Ansible之安裝部署及經常使用模塊的使用介紹
http://yanshisan.blog.51cto.com/7879234/138440
Ansible狀態管理
http://xdays.info/ansible%E7%8A%B6%E6%80%81%E7%AE%A1%E7%90%86.html
ansible學習筆記(二)初始化操做系統:ansible變量使用
http://laowafang.blog.51cto.com/251518/1418471