如何源码安装ansible
ansible可以采用yum的方法进行安装,yum源中是什么版本就只能安装什么版本。如果想要安装最新版本或者历史版本,那只能采用编译源码的方式进行安装了。
操作方法
- 01
安装一些基础软件包 yum -y install xz wget gcc make gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel
- 02
下载所有需要编译的源码包,下载完成一共是11个安装包 wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz --no-check-certificate wget https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz --no-check-certificate wget https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.1.tar.gz --no-check-certificate wget http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz --no-check-certificate wget https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.11.tar.gz --no-check-certificate wget https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.9.3.tar.gz --no-check-certificate wget https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.3.tar.gz --no-check-certificate wget https://pypi.python.org/packages/source/e/ecdsa/ecdsa-0.11.tar.gz --no-check-certificate wget https://pypi.python.org/packages/source/p/paramiko/paramiko-1.15.1.tar.gz --no-check-certificate wget https://pypi.python.org/packages/source/s/simplejson/simplejson-3.6.5.tar.gz --no-check-certificate wget https://github.com/ansible/ansible/archive/v1.7.2.tar.gz --no-check-certificate
- 03
ansible需要python2.7及以上,centos6.5自带的python版本为2.6.6,需要升级到2.7,python是编译安装以下源码包的基础 tar zxvf Python-2.7.8.tgz cd Python-2.7.8 ./configure --enable-shared --enable-loadable-sqlite-extensions --with-zlib make make install mv /usr/bin/python /usr/bin/python2.6.6 ln -s /usr/local/bin/python2.7 /usr/bin/python echo -e "/usr/local/lib" >>/etc/ld.so.conf /sbin/ldconfig /sbin/ldconfig -v sed -i 's@#!/usr/bin/python@#!/usr/bin/python2.6.6@' /usr/bin/yum
- 04
严格按照下列顺序依次编译安装源码包 tar xvzf setuptools-7.0.tar.gz cd setuptools-7.0 python setup.py install tar xvzf pycrypto-2.6.1.tar.gz cd pycrypto-2.6.1 python setup.py install CHECK_RUN "pycrypto_install" >>setup.log 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 tar xvzf PyYAML-3.11.tar.gz cd PyYAML-3.11 python setup.py install tar xvzf MarkupSafe-0.9.3.tar.gz cd MarkupSafe-0.9.3 python setup.py install tar xvzf Jinja2-2.7.3.tar.gz cd Jinja2-2.7.3 python setup.py install tar xvzf ecdsa-0.11.tar.gz cd ecdsa-0.11 python setup.py install tar xvzf paramiko-1.15.1.tar.gz cd paramiko-1.15.1 python setup.py install tar xvzf simplejson-3.6.5.tar.gz cd simplejson-3.6.5 python setup.py install
- 05
从githup上下载的源码包需要重命名 mv v1.7.2.tar.gz ansible-1.7.2.tar.gz tar xvzf ansible-1.7.2.tar.gz cd ansible-1.7.2 python setup.py install
- 06
拷贝ansible配置文件,并定义主机 mkdir -p /etc/ansible cp /root/source/ansible-1.7.2/examples/ansible.cfg /etc/ansible/ansible.cfg vim /etc/ansible/ansible.cfg remote_port = 36000 private_key_file = /root/.ssh/id_rsa [root@localhost ~]# cat /etc/ansible/hosts [test] 192.168.1.116
- 07
安装完成之后,用命令测试并使用 ansible 192.168.1.116 -m shell -a "uptime" -k