0

我正在尝试使用 Ansible (v 1.3.3) 创建一个剧本,以便按照Pythonbrew 自述文件中的说明在 Debian 服务器上安装 Pythonbrew 系统范围。

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

这是我的剧本脚本:

- 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] => {“更改”: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”}标准错误:/bin/bash:pythonbrew:找不到命令

在过去的一个小时左右,我一直在调整东西,但无济于事。有人对解决此问题有任何建议吗?

4

1 回答 1

1

通过查看PythonBrew 安装脚本,我能够弄清楚这一点。(正好赶上 PythonBrew 的弃用!)

这是无需人工干预即可安装 PythonBrew 的剧本。任何尝试编写 PythonBrew 脚本以自动安装的人都可能对此感兴趣。

变量.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

---

#
# 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
于 2013-10-23T20:58:03.280 回答