首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Ansible,如何安装PythonBrew系统?

使用Ansible,如何安装PythonBrew系统?
EN

Stack Overflow用户
提问于 2013-10-11 22:30:45
回答 1查看 828关注 0票数 0

我正在尝试创建一个带有Ansible (v1.3.3)的剧本,以便按照Pythonbrew文件中的说明在Debian服务器上安装Pythonbrew。

我能够安装Python,但是我无法安装我想要的Python的特定版本。我怀疑这个问题与当前运行的shell环境有关。

这是我的剧本:

代码语言:javascript
复制
- name: Install and configure PythonBrew
  hosts: dev
  user: root
  vars_files:
    - vars.yml
  gather_facts: false

  tasks:
    - name: Install PythonBrew Debian packages
      apt: pkg=${item} state=installed update-cache=yes
      with_items: ${pythonbrew_packages}

    - name: Install PythonBrew system-wide
      shell: curl -kL http://xrl.us/pythonbrewinstall | bash creates=/usr/local/pythonbrew executable=/bin/bash

    - name: Update bashrc for PythonBrew
      lineinfile:
        dest=~/.bashrc
        regexp='^'
        line='[[ -s $HOME/.pythonbrew/etc/bashrc ]] && source $HOME/.pythonbrew/etc/bashrc'
        state=present
        create=True

    - name: Install python binary
      shell: pythonbrew install -v ${python_version} executable=/bin/bash

当我运行这个剧本时,它会失败,输出如下

失败: devserver => {“已更改”:真,"cmd":"pythonbrew -v 2.7.3 ","delta":"0:00:00.016639","end":"2013-10-11 15:21:40.989677","rc":127,"start":"2013-10-11 15:21:40.973038"} stderr: /bin/bash: pythonbrew:命令找不到

在过去的一个小时里,我一直在调整事情,但没有结果。有人对此有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-23 20:58:03

通过偷看PythonBrew安装脚本,我就能弄明白这一点。(正好赶上对PythonBrew的否定!)

下面是在不需要人工干预的情况下安装PythonBrew的剧本。这可能是任何试图脚本PythonBrew自动安装的人感兴趣的。

vars.yml

代码语言:javascript
复制
#
# Python/PythonBrew Settings
# TODO: replace old-style Ansible ${vars} with jinja-style {{ vars }}
#
project_name: MY_PROJECT

python:
  version: 2.7.3

pythonbrew:
  root: /usr/local/pythonbrew
  bashrc_path: $HOME/.pythonbrew/etc/bashrc

  packages:
    - curl
    - zlib1g-dev
    - libsqlite3-dev
    - libssl-dev
    - libxml2
    - libxml2-dev
    - libxslt1-dev
    - libmysqlclient-dev
    - libbz2-dev

pythonbrew.yml

代码语言:javascript
复制
---

#
# Install and Configure PythonBrew
#
- name: Install and configure PythonBrew
  hosts: MY_HOST
  user: root
  vars_files:
    - vars.yml
  gather_facts: false

  tasks:
    - name: Install PythonBrew Debian packages
      apt: pkg=${item} state=installed update-cache=yes
      with_items: ${pythonbrew.packages}

    - name: Install PythonBrew system-wide
      shell: curl -kL http://xrl.us/pythonbrewinstall | bash
        executable=/bin/bash
        creates=${pythonbrew.root}

    - name: Update bashrc for PythonBrew
      lineinfile:
        dest=/root/.bashrc
        regexp='^'
        line='[[ -s ${pythonbrew.bashrc_path} ]] && source ${pythonbrew.bashrc_path}'
        state=present
        create=True

    # This step allows install to continue without new shell. Pulled from:
    # https://github.com/utahta/pythonbrew/blob/master/pythonbrew/installer/pythonbrewinstaller.py#L91
    - name: Install python binary
      shell: export PYTHONBREW_ROOT=${pythonbrew.root}; source ${pythonbrew.root}/etc/bashrc; pythonbrew install ${python.version}
        executable=/bin/bash

    - name: Switch to python version
      shell: export PYTHONBREW_ROOT=${pythonbrew.root}; source ${pythonbrew.root}/etc/bashrc; pythonbrew switch ${python.version}
        executable=/bin/bash
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19328252

复制
相关文章

相似问题

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