john84 john84 - 1 month ago 16
Python Question

Provisioning CoreOS with Ansible pip error

I am trying to provision a coreOS box using Ansible. First a bootstapped the box using https://github.com/defunctzombie/ansible-coreos-bootstrap

This seems to work ad all but pip (located in /home/core/bin) is not added to the path. In a next step I am trying to run a task that installs docker-py:

- name: Install docker-py
pip: name=docker-py


As pip's folder is not in path I did it using ansible:

environment:
PATH: /home/core/bin:$PATH


If I am trying to execute this task I get the following error:

fatal: [192.168.0.160]: FAILED! => {"changed": false, "cmd": "/home/core/bin/pip install docker-py", "failed": true, "msg": "\n:stderr: /home/core/bin/pip: line 2: basename: command not found\n/home/core/bin/pip: line 2: /root/pypy/bin/: No such file or directory\n"}

what I ask is where does
/root/pypy/bin/
come from it seems this is the problem. Any idea?

Answer Source

You can't use shell-style variable expansion when setting Ansible variables. In this statement...

environment:
  PATH: /home/core/bin:$PATH

...you are setting your PATH environment variable to the literal value /home/core/bin:$PATH. In other words, you are blowing away any existing value of $PATH, which is why you're getting "command not found" errors for basic things like basename.

Consider installing pip somewhere in your existing $PATH, modifying $PATH before calling ansible, or calling pip from a shells cript:

- name: install something with pip
  shell: |
    PATH="/home/core/bin:$PATH"
    pip install some_module