编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

运维自动化工具Ansible新版本环境安装以及搭建

wxchong 2024-07-02 03:08:49 开源技术 12 ℃ 0 评论

环境说明

ansible主程序安装:192.168.1.71上,centos6.5,64位操作系统

1、下载必要软件包(软件版本基本上都为最新的,基本上均为2016年更新的软件)

Python:2.7.12

# wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz

setuptools:28.6.1

# wget https://pypi.python.org/packages/b5/9a/9ce1a45a076f977cb870bf0c9370347c9371b0e9aa9ca9859196ce58afda/setuptools-28.6.1.tar.gz#md5=b8df391e7532b544e16e1e4cc35a90e5

pycrypto:2.6.1

# wget https://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.1.tar.gz

yaml:0.1.7

# wget http://pyyaml.org/download/libyaml/yaml-0.1.7.tar.gz

PyYAML:3.12

# wget http://pyyaml.org/download/pyyaml/PyYAML-3.12.tar.gz

MarkupSafe:0.23

# wget https://pypi.python.org/packages/c0/41/bae1254e0396c0cc8cf1751cb7d9afc90a602353695af5952530482c963f/MarkupSafe-0.23.tar.gz#md5=f5ab3deee4c37cd6a922fb81e730da6e

Jinja2:2.7.3

# wget https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.3.tar.gz

ecdsa:0.13

# wget https://pypi.python.org/packages/f9/e5/99ebb176e47f150ac115ffeda5fedb6a3dbb3c00c74a59fd84ddf12f5857/ecdsa-0.13.tar.gz#md5=1f60eda9cb5c46722856db41a3ae6670

paramiko:1.15.1

# wget https://pypi.python.org/packages/source/p/paramiko/paramiko-1.15.1.tar.gz

simplejson:3.8.2

# wget https://pypi.python.org/packages/source/s/simplejson/simplejson-3.8.2.tar.gz

Ansible:2.1.2.0

# wget https://pypi.python.org/packages/5f/51/9f54f20180eb323a80451c9f48f508bd5bbe03008c136e125b4ce3946fcf/ansible-2.1.2.0.tar.gz


2、安装已下载的软件

(1)Python:2.7.12安装

# tar xf Python-2.7.12.tgz

# cd Python-2.7.12

# ./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 /usr/bin/python

## 修改yum脚本,使其指向旧版本的python,已避免其无法运行

# vim /usr/bin/yum

将首行:#!/usr/bin/python 修改成 #!/usr/bin/python2.6

检查yum使用使用正常

# yum list

# yum clean all

# yum list

(2)setuptools:28.6.1安装

# tar xf setuptools-28.6.1.tar.gz

# cd setuptools-28.6.1

# python setup.py install

(3)pycrypto:2.6.1

# tar xf pycrypto-2.6.1.tar.gz

# cd pycrypto-2.6.1

# python setup.py install

(4)yaml:0.1.7 和 PyYAML:3.12 安装

# tar xf yaml-0.1.7.tar.gz

# cd yaml-0.1.7

# ./configure --prefix=/usr/local

# make --jobs=`grep processor /proc/cpuinfo | wc -l`

# make install

# cd ..

# tar xf PyYAML-3.12.tar.gz

# cd PyYAML-3.12

# python setup.py install

(5)MarkupSafe:0.23 和 Jinja2:2.7.3 安装

# tar xf MarkupSafe-0.23.tar.gz

# cd MarkupSafe-0.23

# python setup.py install

# cd ..

# tar xf Jinja2-2.7.3.tar.gz

# cd Jinja2-2.7.3

# python setup.py install

(6)ecdsa:0.13 和 paramiko:1.15.1 安装

# tar xf ecdsa-0.13.tar.gz

# cd ecdsa-0.13

# python setup.py install

# cd ..

# tar xf paramiko-1.15.1.tar.gz

# cd paramiko-1.15.1

# python setup.py install

(7)simplejson:3.8.2安装

# tar xf simplejson-3.8.2.tar.gz

# cd simplejson-3.8.2

# python setup.py install

(8)Ansible:2.1.2.0安装

安装过程可能会报出gcc的错误,如下:

error: Setup script exited with error: command 'gcc' failed with exit status 1

# yum -y install zlib-dev openssl-devel sqlite-devel bzip2-devel libxslt-devel libffi-devel

# tar xf ansible-2.1.2.0.tar.gz

# cd ansible-2.1.2.0

# python setup.py install

到此为止,软件的准备和安装都已经完成。


3、简单的测试

(1)ssh免密码秘钥对验证

# ssh-copy-id -i ~/.ssh/id_rsa.pub "-p 22612 ihavecar@192.168.1.74"

# ssh-copy-id -i ~/.ssh/id_rsa.pub "-p 22612 ihavecar@192.168.1.49"

(2)ansible配置

将前面解压出来的ansible里面的example中的所有文件拷贝到/etc/ansible/;

# cp /home/app/soft/ansible/ansible-2.1.2.0/examples/* /etc/ansible/

# cd /etc/ansible/

# vim /etc/ansible/ansible.cfg

……

remote_port = 22612

remote_user = ihavecar

……

## 主机组定义

$ cat hosts

[ansihost]

192.168.1.49

192.168.1.74

(3)测试

# ansible testhost -m command -a 'uptime'

192.168.1.49 | SUCCESS | rc=0 >>

11:52:41 up 3 days, 18:54, 2 users, load average: 0.00, 0.00, 0.00

192.168.1.74 | SUCCESS | rc=0 >>

11:52:43 up 2 days, 1:00, 3 users, load average: 0.00, 0.00, 0.00

说明:第一次运行时,需要输入一下“yes”【进行公钥验证】,后续无需再次输入。

到此为止,已经是测试通过。等待其他的模块以及功能点的测试。

后续会继续连载其他模块以及功能点测试文章,敬请关注,谢谢。

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表