目的
利用pip安装teseinfra的时候总会爆出下面的问题
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
- 所以要升级python版本,Centos默认情况下Python是被安装了的,因为yum本省就是python写的,python的默认安装时在
/usr/bin/python
,如果参照这个来通过ansible来实现的话,有两个问题
- 需要修正yum的配置(/usr/bin/yum)
- 里面有一句话
mv /usr/bin/python /usr/bin/python.26
这个做完后,后面所有的都会爆出找不到/usr/bin/python
开始我利用ansible 打算重新做成这个文件,但是总是爆出找不到/usr/bin/python
,最后才恍然大悟,ansible在目标机器上就是利用python来执行的, 做完mv /usr/bin/python /usr/bin/python.26
Python已经没有了,当然后面写什么都不行
最后决定参照这个来写ansible
python.yml
- name: Download Python ({{ python_ver }})
get_url: >
url=https://www.python.org/ftp/python/{{ python_ver }}/Python-2.7.13.tgz
dest={{ src_dir }}/Python-{{ python_ver }}.tgz
- name: Unarchive Python
unarchive: src={{ src_dir }}/Python-{{ python_ver }}.tgz dest={{ src_dir }} copy=no
- name: Install Python
command: >
{{ item }}
chdir={{ src_dir }}/Python-{{ python_ver }}/
creates=/usr/local/bin/python
with_items:
- './configure CFLAGS=-fPIC --enable-shared --prefix=/usr/local/'
- make
- make install
- name: Link Python lib
file: src=/usr/local/lib/libpython2.7.so.1.0 dest=/lib64/libpython2.7.so.1.0 state=link
- name: download pip
get_url:
url=https://bootstrap.pypa.io/get-pip.py
dest={{ src_dir }}/get-pip.py
- name: install pip
shell: |
cd {{ src_dir }}
/usr/local/bin/python2.7 get-pip.py
ln -sf /usr/local/bin/pip /usr/bin/pip
- name: install testinfra
shell: |
pip install --upgrade pip
pip install --upgrade pytest
pip install testinfra
- ansible.yml (用yum来安装的话ansible会安装到
/usr/bin/ansible
但是通过上面安装的testinfra 会找不到ansible ,此时pip是/usr/local/bin/pip
此时用pip来安装ansible的话,也会在/usr/local/bin/ansible
#- name: install ansible
# yum: name="{{ item }}" state=latest enablerepo=epel
# with_items:
# - sshpass
# - ansible
- name: install ansible by pip
command: pip install ansible==2.2.2