溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Linux下ansible如何安裝

發布時間:2022-02-17 11:30:35 來源:億速云 閱讀:203 作者:小新 欄目:開發技術

這篇文章給大家分享的是有關Linux下ansible如何安裝的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

ansible是新出現的自動化運維工具,基于Python開發,集合了眾多運維工具(puppet、chef、func、fabric)的優點,實現了批量系統配置、批量程序部署、批量運行命令等功能。

Linux下ansible如何安裝

Ansible的安裝

1、yum源安裝

以centos為例,默認在源里沒有ansible,不過在fedora epel源里有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 進行安裝,不過本部分既然提到的是源碼安裝,主要針對的無法上外網的情況下,可以通過pypi 站點搜索以上包,下載后通過python setup.py install 進行安裝。

最后通過github或pypi上下載ansible源碼包,通過python setup.py install 安裝即可。由于安裝過程相對簡單,這里略過,主要介紹安裝后,可能遇到的問題。

a、安裝PyYAML時,報錯如下:

# python setup.py installlibyaml 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 -hTraceback (most recent call last):
File "/usr/local/src/ansible-devel/bin/ansible", line 36, infrom ansible.runner import Runner
File "/usr/local/src/ansible-devel/lib/ansible/runner/__init__.py", line 62, infrom Crypto.Random import atfork
File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, infrom Crypto.Random import _UserFriendlyRNG
File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, infrom Crypto.Random.Fortuna import FortunaAccumulator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, inimport FortunaGenerator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, infrom Crypto.Util.number import ceil_shift, exact_log2, exact_div
File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, inif _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, inFile "/usr/lib/python2.6/site-packages/paramiko/__init__.py", line 69, infrom transport import randpool, SecurityOptions, Transport
File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 32, infrom paramiko import util
File "/usr/lib/python2.6/site-packages/paramiko/util.py", line 32, infrom paramiko.common import *
File "/usr/lib/python2.6/site-packages/paramiko/common.py", line 98, infrom rng import StrongLockingRandomPool
File "/usr/lib/python2.6/site-packages/paramiko/rng.py", line 22, infrom Crypto.Util.randpool import RandomPool as _RandomPool
File "/usr/lib64/python2.6/site-packages/Crypto/Util/randpool.py", line 30, inimport Crypto.Random
File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, infrom Crypto.Random import _UserFriendlyRNG
File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, infrom Crypto.Random.Fortuna import FortunaAccumulator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, inimport FortunaGenerator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, infrom Crypto.Util.number import ceil_shift, exact_log2, exact_div
File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, inif _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 buildrunning 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

安裝sshpass程序。默認源里沒有,我這里選擇直接從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如何安裝”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女