千家信息网

Linux下怎么安装Ansible

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,本篇内容主要讲解"Linux下怎么安装Ansible",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Linux下怎么安装Ansible"吧!1、yum源安装
千家信息网最后更新 2026年11月01日Linux下怎么安装Ansible

本篇内容主要讲解"Linux下怎么安装Ansible",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Linux下怎么安装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 tospecify the option --include-dirs or uncomment andmodify the parameter include_dirs in setup.cfg)running install_librunning install_egg_infoRemoving /usr/lib64/python2.6/site-packages/PyYAML-3.11-py2.6.egg-infoWriting /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 RunnerFile "/usr/local/src/ansible-devel/lib/ansible/runner/__init__.py", line 62, infrom Crypto.Random import atforkFile "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, infrom Crypto.Random import _UserFriendlyRNGFile "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, infrom Crypto.Random.Fortuna import FortunaAccumulatorFile "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, inimport FortunaGeneratorFile "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, infrom Crypto.Util.number import ceil_shift, exact_log2, exact_divFile "/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 paramikoTraceback (most recent call last):File "", line 1, inFile "/usr/lib/python2.6/site-packages/paramiko/__init__.py", line 69, infrom transport import randpool, SecurityOptions, TransportFile "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 32, infrom paramiko import utilFile "/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 StrongLockingRandomPoolFile "/usr/lib/python2.6/site-packages/paramiko/rng.py", line 22, infrom Crypto.Util.randpool import RandomPool as _RandomPoolFile "/usr/lib64/python2.6/site-packages/Crypto/Util/randpool.py", line 30, inimport Crypto.RandomFile "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, infrom Crypto.Random import _UserFriendlyRNGFile "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, infrom Crypto.Random.Fortuna import FortunaAccumulatorFile "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, inimport FortunaGeneratorFile "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, infrom Crypto.Util.number import ceil_shift, exact_log2, exact_divFile "/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 buildrunning build_pyrunning build_extrunning build_configurewarning: 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 attackvulnerability.", 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 program10.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.com10.212.52.14 ansible_ssh_user=root ansible_ssh_pass=abc12310.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.3510.212.52.16 | success | rc=0 >>18:09pm up 329 days 1:01, 2 users, load average: 0.08, 0.03, 0.0510.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"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

配置 可以通过 文件 源码 版本 密码 验证 模块 三台 上下 内容 情况 方式 方法 注释 示例 系统 问题 学习 不对 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 科技金融是不是互联网金融 科技和互联网公司 互联网电商科技 科技互联网公司装修 网络科技有限互联网 喔噻互联网科技 为想互联网科技 互联网与新科技 深圳期待互联网科技 团飞科技与伯堂互联网服务平台 互联网科技研发水平 互联网科技圈年度人物 高科技互联网套路 小米互联网科技园入驻 互联网公司高科技产品 南京一网一红互联网科技有限公司 上海乐五互联网科技有限公司 江苏互联网智能科技产品出厂价 深圳互联网科技园地址 中国主要互联网科技公司 上海喔噻互联网科技有限公司 广州互联网络科技有限公司 北京禾田雨橡互联网科技 苏州大垚互联网科技 深圳前海聚择互联网科技有限公司 南山科技园互联网公司有哪些 互联网科技项目计划书材料类 开一家科技互联网公司需要多少钱 乌苏新华互联网科技做什么的 互联网高科技绘画
0