運維自動化工具ansible(安裝)
阿新 • • 發佈:2017-06-21
down 免密鑰 org roo bin package python2 div 5.1
一、安裝
註意:強烈建議升級python版本到2.6以上,不然運行會出錯或者有些功能會沒有,在編譯安裝其他包的時候也會因為兼容問題報錯。
(1)、python2.7安裝
https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz # tar xvzf Python-2.7.8.tgz # cd Python-2.7.8 # ./configure --prefix=/usr/local # make # make install
## 將python頭文件拷貝到標準目錄,以避免編譯ansible時,找不到所需的頭文件
# cd /usr/local/include/python2.7 # cp -a ./* /usr/local/include/
## 備份舊版本的python,並符號鏈接新版本的python
# cd /usr/bin # mv python python.old # ln -s /usr/local/bin/python2.7 /usr/local/bin/python # rm -f /usr/bin/python && cp /usr/local/bin/python2.7 /usr/bin/python
## 修改yum腳本,使其指向舊版本的python,已避免其無法運行
# vim /usr/bin/yum #!/usr/bin/python --> #!/usr/bin/python2.4
(2)、setuptools模塊安裝
https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz # tar xvzf setuptools-7.0.tar.gz # cd setuptools-7.0 # python setup.py install
安裝好setuptools後就可以利用easy_install這個工具安裝下面的python模塊了,但本機是虛擬機,配置太低,所以基本無法安裝,所以只好一個一個下載下來進行安裝。
(3)、pycrypto模塊安裝
https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.1.tar.gz # tar xvzf pycrypto-2.6.1.tar.gz # cd pycrypto-2.6.1 # python setup.py install
(4)、PyYAML模塊安裝
http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz # tar xvzf 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
https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.11.tar.gz # tar xvzf PyYAML-3.11.tar.gz # cd PyYAML-3.11 # python setup.py install
(5)、Jinja2模塊安裝
https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.9.3.tar.gz # tar xvzf MarkupSafe-0.9.3.tar.gz # cd MarkupSafe-0.9.3 # python setup.py install
https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.3.tar.gz # tar xvzf Jinja2-2.7.3.tar.gz # cd Jinja2-2.7.3 # python setup.py install
(6)、paramiko模塊安裝
https://pypi.python.org/packages/source/e/ecdsa/ecdsa-0.11.tar.gz # tar xvzf ecdsa-0.11.tar.gz # cd ecdsa-0.11 # python setup.py install
https://pypi.python.org/packages/source/p/paramiko/paramiko-1.15.1.tar.gz # tar xvzf paramiko-1.15.1.tar.gz # cd paramiko-1.15.1 # python setup.py install
(7)、simplejson模塊安裝
https://pypi.python.org/packages/source/s/simplejson/simplejson-3.6.5.tar.gz # tar xvzf simplejson-3.6.5.tar.gz # cd simplejson-3.6.5 # python setup.py install
(8)、ansible安裝
https://github.com/ansible/ansible/archive/v1.7.2.tar.gz # tar xvzf ansible-1.7.2.tar.gz # cd ansible-1.7.2 # python setup.py install
(9)、SSH免密鑰登錄設置
## 生成公鑰/私鑰 # ssh-keygen -t rsa -P ‘‘ ## 寫入信任文件(將/root/.ssh/id_rsa_storm1.pub分發到其他服務器,並在所有服務器上執行如下指令): # cat /root/.ssh/id_rsa_storm1.pub >> /root/.ssh/authorized_keys # chmod 600 /root/.ssh/authorized_keys
(10)、拷貝,生成ansible配置文件
a 配置文件/etc/ansible/ansible.cfg # mkdir -p /etc/ansible #cp ansible-1.7.2/examples/ansible.cfg /etc/ansible/ b 配置文件/etc/ansible/hosts # vim /etc/ansible/hosts [test] 192.168.110.20 192.168.110.30
測試
# ansible test -m command -a ‘uptime‘ ## 用來測試遠程主機的運行狀態 # ansible test -m ping
參看所有的參數
ansible-doc -l
運維自動化工具ansible(安裝)