2

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?

2
  • Just from looking at the error message, it seems like basename: command not found is the root issue that's probably causing the /root/pypy/bin/ one. Oct 17, 2016 at 21:00
  • One interesting fact if I ssh into the box and run home/core/bin/pip install docker-py the Command executes without any problems. The failure only occurs if I run it from Ansible.
    – john84
    Oct 17, 2016 at 21:04

2 Answers 2

2

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
4
  • Thanks for your response, calling pip using a shell script in ansible creates unfortunately the same error.
    – john84
    Oct 18, 2016 at 21:08
  • Are you sure you're no longer trying to set PATH in Ansible? Maybe update your question with your new playbook.
    – larsks
    Oct 18, 2016 at 21:21
  • Hey, yes pretty shure, my yml looks as follows: - hosts: rancher-server remote_user: coreos gather_facts: True become: yes become_method: sudo tasks: - name: install something with pip shell: | PATH="/home/core/bin:$PATH" pip install some_module
    – john84
    Oct 18, 2016 at 21:28
  • Ok my mistake - hosts: rancher-server remote_user: coreos tasks: - name: install something with pip shell: | PATH=/home/core/bin:$PATH pip install docker-py Thank you very much
    – john84
    Oct 18, 2016 at 21:42
0

The problem lies in /home/core/bin/pip script which is literally:

#!/bin/bash
LD_LIBRARY_PATH=$HOME/pypy/lib:$LD_LIBRARY_PATH $HOME/pypy/bin/$(basename $0) $@

when run under root by ansible the $HOME variable is substituted with /root and not with /home/core. Change $HOME with /home/core and it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.