首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用Ansible安装python3.4.3

如何使用Ansible安装python3.4.3
EN

Stack Overflow用户
提问于 2015-09-13 13:06:32
回答 1查看 13.6K关注 0票数 4

我想通过使用pyenv和ansible来安装python3.x。

代码语言:javascript
复制
- name: install pyenv
  git: >
    repo=https://github.com/pyenv/pyenv.git
    dest=/home/www/.pyenv
    accept_hostkey=yes
    become: yes
    become_user: www

- name: enable pyenv
  shell: |
    echo 'export PYENV_ROOT="/home/www/.pyenv"' >> /home/www/.bashrc
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> /home/www/.bashrc
    echo 'eval "$(pyenv init -)"' >> /home/www/.bashrc
- name: install python
  shell: pyenv install 3.4.3

如何在ansible中安装python3.x?

EN

回答 1

Stack Overflow用户

发布于 2018-01-31 03:08:22

所以这里就是我使用ansible安装任何版本的python并将其作为替代安装的好方法。我首先运行了configuremake,后来压缩了结果,因为这需要一段时间,然后使用镜像重新分发文件,这样我就可以运行make altinstall了。下面是食谱:

代码语言:javascript
复制
---
# Check the alt python3 version
- name: check alt python version
  shell: /usr/local/bin/python3.6 --version
  register: python3_version
  ignore_errors: yes  # If not installed
  tags:
    - python-alt

# Stuff I did manually to compile everything first by hand
# Python3 alt-install - steps to create binary:
# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
# tar xf Python-3.6.4.tgz
# mv Python-3.6.4 Python-3.6.4-binary && cd Python-3.6.4-binary
# ./configure --prefix=/usr/local --enable-optimizations
# cd .. && tar -zcvf Python-3.6.4-binary.tar.gz Python-3.6.4-binary (upload to mirror servers)
# make && sudo make altinstall UNINST=1
- name: download and unpack alternative python3
  unarchive:
    src: http://www.yourmirror.com/centos/python/Python-3.6.4-binary.tar.gz dest=/tmp/Python-3.6.4-binary.tar.gz
    dest: /tmp
    remote_src: yes
    keep_newer: yes
  when: python3_version['stderr'] != 'Python 3.6.4'
  tags:
    - python-alt

# Its possible to install (instead of altinstall) python3 here
- name: make install alt python3
  make:
    chdir: /tmp/Python-3.6.4-binary
    target: altinstall
    params:
      UNINST: 1  # Replace
  when: python3_version['stderr'] != 'Python 3.6.4'
  become: yes
  tags:
    - python-alt

- name: download get-pip.py
  get_url:
    url: https://bootstrap.pypa.io/get-pip.py
    dest: /tmp/get-pip.py
    mode: 0664
  tags:
    - python-alt

- name: install pip for python3
  shell: /usr/local/bin/python3.6 /tmp/get-pip.py
  become: yes
  tags:
    - python-alt

# We need virtualenv installed under py3 for the virtualenv command to work
- pip:
    name: virtualenv
    executable: /usr/local/bin/pip3.6
  become: True
  tags:
    - python-alt

如果希望在服务器上编译所有内容,可以在执行altinstall步骤之前执行以下操作,并下载源代码包而不是预编译的tar。我不推荐用这种方式,因为它会占用资源,而且你不想用prod来做。以Python2.7.14为例:

代码语言:javascript
复制
---
# Build the default target
- debug:
    var: python2_version
  tags:
    - python_alt
- make:
    chdir: /tmp/Python-2.7.14-binary
  when: python2_version['stderr'] != 'Python 2.7.14'
  tags:
    - python_alt
- name: configure target command
  command: ./configure --prefix=/usr/local --enable-optimizations chdir=/tmp/Python-2.7.14-binary
  when: python2_version['stderr'] != alt_python_version
  tags:
    - python_alt
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32546506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档