Chinaunix首页 | 论坛 | 博客
  • 博客访问: 23255
  • 博文数量: 4
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 40
  • 用 户 组: 普通用户
  • 注册时间: 2018-04-14 11:46
个人简介

专业打杂,挨踢

文章分类

全部博文(4)

文章存档

2018年(4)

我的朋友

分类: 系统运维

2018-05-18 18:51:51

在公司的项目场景中客户机存在众多比较老版本centos5系统。centos5系统默认的python版本为python2.4

ansible官网提供的信息为,当客户机版本低于python 2.5 ,还需要额外安装一个模块python-simplejson
通过在ansible服务器测试,版本2.5.0,客户机安装python-simplejson并不能兼容。客户机已经安装了python-simplejson
[root@ids tmp]# rpm -qa | grep simple
python-simplejson-2.0.9-8.el5

ansible服务器版本如下:

[root@mon ]# ansible --version

ansible 2.5.0

  config file = /etc/ansible/ansible.cfg

  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']

  ansible python module location = /usr/lib/python2.6/site-packages/ansible

  executable location = /usr/bin/ansible

  python version = 2.6.6 (r266:84292, Sep  4 2013, 07:46:00) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]

客户机的python版本如下:

[root@ids tmp]# /usr/bin/python2.4

Python 2.4.3 (#1, Dec 22 2011, 12:12:01)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>


因为客户机python2.4,在ansible 服务器端执行yaml剧本报错,python版本不兼容。

FAILED! => {"changed": false, "module_stderr": "", "module_stdout": "  File \"/tmp/ansible_TzHcPA/ansible_module_setup.py\", line 7\r\n    from __future__ import absolute_import, division, print_function\r\nSyntaxError: future feature absolute_import is not defined\r\n", "msg": "MODULE FAILURE", "rc": 1}


因此需要对项目场景中centos5.0系统的python版本进行升级。

通过使用ansible raw模块升级python,raw模块并不依赖于客户机python版本。升级之后就可以使用ansible的所有功能。

整个过程如下:

1、  下载python2.7安装包

2、  在ansbile服务器通过scp python2.7源码包到客户机

3、  编写升级python的yaml剧本文件,通过ansible raw模块完成python2.7升级。

4、  客户机完成升级后,ansible便可以使用全部功能。

通过wgetpython2.7源码下载到本地,放置在/etc/ansible目录下

[root@mon ansible]# pwd

/etc/ansible

[root@monitor ansible]# ll Python-2.7.2.tgz

-rw-r--r-- 1 root root 14091337 May 17 19:19 Python-2.7.2.tgz

因为客户机的python版本此时为2.4,无法使用Ansiblecopy模块。只能使用scp拷贝源码文件至客户机/tmp目录

[root@mon ansible]# scp Python-2.7.2.tgz mon@211.x.x.x:/tmp

monitor@211.x.x.x's password:

Python-2.7.2.tgz  100%   13MB  13.4MB/s   00:00   

[root@monitor ansible]#

编写python升级的yaml文件

[root@mon ansible]# more python.yaml

---

- name: install python27

  hosts: centos5

  remote_user: monitor

  gather_facts: false

  become: yes

  tasks:

     - name: tar python.tgz

       raw: cd /tmp;tar -zxvf Python-2.7.2.tgz

     - name: install Python27

       raw: cd /tmp/Python-2.7.2;./configure ; make&& make install

     - name: create softlink to python

       raw: mv /usr/bin/python /usr/bin/pythonbak ;ln -s /usr/local/bin/python2.7 /usr/bin/python

     - name: yum env

       raw: sed -ibak '1d' /usr/bin/yum ; sed -i '1i\#!/usr/bin/python2.4' /usr/bin/yum

整个yaml文件使用raw模块,因为raw模块是不依赖于客户机python的。

yaml文件内容为:
进行解压,执行编译脚本,make完成编译和安装,同时备份原有的老版本的python,做软连接。

由于centos5的yum默认使用的为python2.4,为确保yum能正常使用,需要在raw模块里调用sed修改为原有的python2.4版本。


通过ansible-playbook完成centos客户机的python2.7编译,安装,创建软连接和修改yum工具python版本号。


为了演示过程,这里我们检查一下客户机。

检查客户机,版本已经升级至2.7

[root@ids tmp]# python

Python 2.7.2 (default, May 18 2018, 15:38:57)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>

yum能正常使用

[root@ids tmp]# yum list | more

Loaded plugins: katello, product-id, security, subscription-manager

Updating certificate-based repositories.

Unable to read consumer identity

Installed Packages

Deployment_Guide-en-US.noarch               5.8-1.el5                  installed

Deployment_Guide-zh-CN.noarch               5.8-1.el5                  installed

Deployment_Guide-zh-TW.noarch               5.8-1.el5                  installed

此时,客户机全部完成升级,可以使用ansible全部功能了。


使用项目的yaml剧本,原来客户机python2.4版本的报错,已经不再出现,能正常执行,并且
得到项目想要的结果。



完成。


阅读(3500) | 评论(0) | 转发(0) |
0

上一篇:Shell收集服务器软件的版本信息

下一篇:没有了

给主人留下些什么吧!~~