利用Ansible,將Centos6的python的版本更新到2.7

  • 目的

    • 利用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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章