本文介绍了使用 Ansible,如何在系统范围内安装 PythonBrew?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Ansible (v 1.3.3) 创建一个剧本,以按照 Pythonbrew 自述文件.

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

这是我的剧本:

- 名称:安装和配置 PythonBrew主持人:开发用户:rootvars_files:- vars.yml收集事实:假任务:- 名称:安装 PythonBrew Debian 软件包apt: pkg=${item} state=installed update-cache=yeswith_items: ${pythonbrew_packages}- 名称:在系统范围内安装 PythonBrew外壳: curl -kL http://xrl.us/pythonbrewinstall |bash 创建=/usr/local/pythonbrew 可执行文件=/bin/bash- 名称:更新 PythonBrew 的 bashrc行文件:dest=~/.bashrc正则表达式='^'line='[[ -s $HOME/.pythonbrew/etc/bashrc ]] &&源 $HOME/.pythonbrew/etc/bashrc'状态=存在创建=真- 名称:安装python二进制文件外壳:pythonbrew install -v ${python_version} executable=/bin/bash

当我运行这个剧本时,它失败并显示以下输出

失败:[devserver] => {"changed": true, "cmd": "pythonbrew安装 -v 2.7.3 ", "delta": "0:00:00.016639", "end": "2013-10-1115:21:40.989677", "rc": 127, "start": "2013-10-11 15:21:40.973038"}标准错误:/bin/bash:pythonbrew:找不到命令

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

解决方案

通过查看 PythonBrew 安装脚本,我能够解决这个问题.(而且正好赶上 Python 的 )>

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

vars.yml

## Python/PythonBrew 设置# TODO: 用 jinja-style {{ vars }} 替换旧式 Ansible ${vars}#项目名称:MY_PROJECTPython:版本:2.7.3蟒蛇:根:/usr/local/pythonbrewbashrc_path: $HOME/.pythonbrew/etc/bashrc包:- 卷曲- zlib1g-dev- libsqlite3-dev- libssl-dev- libxml2- libxml2-dev- libxslt1-dev- libmysqlclient-dev- libbz2-dev

pythonbrew.yml

---## 安装和配置 PythonBrew#- 名称:安装和配置 PythonBrew主机:MY_HOST用户:rootvars_files:- vars.yml收集事实:假任务:- 名称:安装 PythonBrew Debian 软件包apt: pkg=${item} state=installed update-cache=yeswith_items: ${pythonbrew.packages}- 名称:在系统范围内安装 PythonBrew外壳: curl -kL http://xrl.us/pythonbrewinstall |猛击可执行文件=/bin/bash创建=${pythonbrew.root}- 名称:更新 PythonBrew 的 bashrc行文件:dest=/root/.bashrc正则表达式='^'line='[[ -s ${pythonbrew.bashrc_path} ]] &&源 ${pythonbrew.bashrc_path}'状态=存在创建=真# 这一步允许安装在没有新 shell 的情况下继续.取自:# https://github.com/utahta/pythonbrew/blob/master/pythonbrew/installer/pythonbrewinstaller.py#L91- 名称:安装python二进制文件外壳:导出 PYTHONBREW_ROOT=${pythonbrew.root};源 ${pythonbrew.root}/etc/bashrc;pythonbrew 安装 ${python.version}可执行文件=/bin/bash- 名称:切换到python版本外壳:导出 PYTHONBREW_ROOT=${pythonbrew.root};源 ${pythonbrew.root}/etc/bashrc;pythonbrew 开关 ${python.version}可执行文件=/bin/bash

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.

I am able to get Pythonbrew installed but I cannot install the specific version of Python that I want with it. I suspect the issue has to do with the shell environment Ansible is running under.

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

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. (And just in time for the deprecation of PythonBrew!)

Here's the playbook that installs PythonBrew without manual intervention. This may be of interest to anyone trying to script PythonBrew to install automatically.

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

---

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

这篇关于使用 Ansible,如何在系统范围内安装 PythonBrew?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 20:54