简体   繁体   English

使用Ansible,如何在系统范围内安装PythonBrew?

[英]Using Ansible, how can I install PythonBrew system-wide?

I'm trying to create a playbook with Ansible (v 1.3.3) to install Pythonbrew system-wide on a Debian server following the instructions in the Pythonbrew readme file . 我正在尝试使用Ansible(v 1.3.3)创建一个剧本,以便按照Pythonbrew自述文件中的说明在系统上在Debian服务器上安装Pythonbrew。

I am able to get Pythonbrew installed but I cannot install the specific version of Python that I want with it. 我可以安装Pythonbrew,但无法安装想要的特定版本的Python。 I suspect the issue has to do with the shell environment Ansible is running under. 我怀疑问题与运行Ansible的外壳环境有关。

Here's my playbook script: 这是我的剧本脚本:

- 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

When I run this playbook, it fails with the following output 当我运行此剧本时,它失败并显示以下输出

failed: [devserver] => {"changed": true, "cmd": "pythonbrew install -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: command not found 失败:[devserver] => {“ changed”:true,“ cmd”:“ pythonbrew install -v 2.7.3”,“ delta”:“ 0:00:00.016639”,“ end”:“ 2013-10-11 15:21:40.989677“,” rc“:127,”开始“:” 2013-10-11 15:21:40.973038“} stderr:/ bin / bash:pythonbrew:命令未找到

I've been tweaking things for the last hour or so to no avail. 在过去一个小时左右的时间内,我一直在进行一些调整,但都无济于事。 Does anybody have any suggestions for fixing this? 有人对此有任何建议吗?

By peeking at the PythonBrew install script , I was able to figure this out. 通过查看PythonBrew安装脚本 ,我能够弄清楚这一点。 (And just in time for the deprecation of PythonBrew !) (正好是弃用PythonBrew的时候 !)

Here's the playbook that installs PythonBrew without manual intervention. 这是无需手动干预即可安装PythonBrew的剧本。 This may be of interest to anyone trying to script PythonBrew to install automatically. 任何试图编写PythonBrew脚本以自动安装的人都可能对此感兴趣。

vars.yml vars.yml

#
# 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 pythonbrew.yml

---

#
# 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM