您好,登錄后才能下訂單哦!
本篇內容主要講解“Linux下怎么安裝Ansible”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Linux下怎么安裝Ansible”吧!
1、yum源安裝
以
為例,默認在源里沒有ansible,不過在 里有ansible,配置完epel 源后,可以直接通過yum 進行安裝。這里以centos6.8為例:# yum install http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm # yum install ansible
2、apt-get安裝
在ubuntu及其衍生版中,可以通過增加ppa源進行apt-get安裝,具體如下:
$ sudo apt-get install software-properties-common $ sudo apt-add-repository ppa:ansible/ansible $ sudo apt-get update $ sudo apt-get install ansible
3、源碼安裝 源碼安裝需要python2.6以上版本,其依賴模塊paramiko、PyYAML、Jinja2、httplib2、simplejson、pycrypto模塊,以上模塊可以通過pip或easy_install 進行安裝,不過本部分既然提到的是源碼安裝,主要針對的無法上外網的情況下,可以通過 搜索以上包,下載后通過python setup.py install 進行安裝。
最后通過
或 下載ansible源碼包,通過python setup.py install 安裝即可。由于安裝過程相對簡單,這里略過,主要介紹安裝后,可能遇到的問題。a、安裝PyYAML時,報錯如下:
# python setup.py install libyaml is not found or a compiler error: forcing --without-libyaml (if libyaml is installed correctly, you may need to specify the option --include-dirs or uncomment and modify the parameter include_dirs in setup.cfg) running install_lib running install_egg_info Removing /usr/lib64/python2.6/site-packages/PyYAML-3.11-py2.6.egg-info Writing /usr/lib64/python2.6/site-packages/PyYAML-3.11-py2.6.egg-info
在centos6.8系統中,可以通過yum -y install libyaml 包解決,或者從ISO文件中提供該包,通過rpm -ivh進行安裝。
b、安裝完ansible是,報錯如下:
[root@361way.com ansible-1.9.1]# ansible -h Traceback (most recent call last): File "/usr/local/src/ansible-devel/bin/ansible", line 36, in from ansible.runner import Runner File "/usr/local/src/ansible-devel/lib/ansible/runner/__init__.py", line 62, in from Crypto.Random import atfork File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in from Crypto.Random import _UserFriendlyRNG File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in from Crypto.Random.Fortuna import FortunaAccumulator File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in import FortunaGenerator File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in from Crypto.Util.number import ceil_shift, exact_log2, exact_div File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC: AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
import paramiko包時,報錯如下:
>>> import paramiko Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/site-packages/paramiko/__init__.py", line 69, in from transport import randpool, SecurityOptions, Transport File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 32, in from paramiko import util File "/usr/lib/python2.6/site-packages/paramiko/util.py", line 32, in from paramiko.common import * File "/usr/lib/python2.6/site-packages/paramiko/common.py", line 98, in from rng import StrongLockingRandomPool File "/usr/lib/python2.6/site-packages/paramiko/rng.py", line 22, in from Crypto.Util.randpool import RandomPool as _RandomPool File "/usr/lib64/python2.6/site-packages/Crypto/Util/randpool.py", line 30, in import Crypto.Random File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in from Crypto.Random import _UserFriendlyRNG File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in from Crypto.Random.Fortuna import FortunaAccumulator File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in import FortunaGenerator File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in from Crypto.Util.number import ceil_shift, exact_log2, exact_div File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC: AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
經網上查找,確認為pycrypto包安裝時依賴的GMP版本不對的問題,具體可以通過以下步驟驗證:
[root@361way.com pycrypto-2.6.1]# python setup.py build running build running build_py running build_ext running build_configure warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
解決方法:
打開 /usr/lib64/python2.6/site-packages/Crypto/Util/number.py 文件,可以 看到 56 行上的注釋說明,要求 libgmp 為 v5 以上版本。而系統現有版本為 4.1.4,把以下兩行暫時注釋掉,Ansible 執行正常。
if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC: _warn("Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)
不過,此方法只是臨時加以解決,更好的方式是去將 libgmp 升級到符合要求的版本。
c、執行時報錯
[root@361way.com src]# ansible test -m raw -a 'uptime' 10.212.52.14 | FAILED => to use the 'ssh' connection type with passwords, you must install the sshpass program 10.212.52.16 | FAILED => to use the 'ssh' connection type with passwords, you must install the sshpass program
安裝
。默認源里沒有,我這里選擇直接從sohu源里下載安裝。三、Ansible的配置與驗證
這里以pypi上下載的源碼內有一個examles包,可以將使用該示例文件做為默認配置,具體如下:
[root@361way.com ansible-1.9.1]# mkdir -p /etc/ansible [root@361way.com ansible-1.9.1]# cp -rp examples/* /etc/ansible/ [root@361way.com ansible-1.9.1]# cd /etc/ansible/
使用默認示例配置文件后,編輯/etc/ansible/hosts文件,通過以下方式驗證ansible是否可用:
[root@361way.com ~]# cat /etc/ansible/hosts [test] 10.212.52.252 ansible_ssh_user=root ansible_ssh_pass=361way.com 10.212.52.14 ansible_ssh_user=root ansible_ssh_pass=abc123 10.212.52.16 ansible_ssh_user=root ansible_ssh_pass=91it.org
以上的配置中,我配置了一個test組,該組下有三臺主機,三臺都使用root驗證,三臺的密碼分別是361way.com、abc123、91it.org 。
注:后面的用戶和密碼項是非必須的,在配置key認證的情況下,不使用密碼也可以直接操作 。未使用key的,也可以在ansible通過 -k參數在操作前詢問手動輸入密碼。
[root@361way.com ~]# ansible test -a 'uptime' 10.212.52.252 | success | rc=0 >> 18:01pm up 21 days 3:24, 3 users, load average: 0.39, 0.38, 0.35 10.212.52.16 | success | rc=0 >> 18:09pm up 329 days 1:01, 2 users, load average: 0.08, 0.03, 0.05 10.212.52.14 | success | rc=0 >> 18:08pm up 329 days 0:23, 2 users, load average: 0.06, 0.06, 0.05
到此,相信大家對“Linux下怎么安裝Ansible”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。