Installing a python package from source using ansible

Viewed 2215

I have the following ansible playbook:

- hosts: all
  gather_facts: false
  sudo: true
  tasks:
  - name: Pull sources from the repository.
    git: repo=https://github.com/mongodb-labs/mongo-connector.git dest=/srv/checkout/mongo-connector

- hosts: all
  sudo: true
  tasks:
  - name: copy local config.json to remote if exists
    local_action: stat path="./config.json"
    register: file
    ignore_errors: True
  - name: copy file if it exists
    copy: src=./config.json dest=/srv/checkout/mongo-connector/config.json force=yes
    when: file.stat.exists

- hosts: all
  sudo: true
  tasks:
  - name: copy local install_mc.sh to remote if exists
    local_action: stat path="./install_mc.sh"
    register: file
    ignore_errors: True
  - name: copy installation scripts
    copy: src=./install_mc.sh dest=/srv/checkout/mongo-connector/install_mc.sh mode=755
    when: file.stat.exists
  - name: Execute script
    script: /srv/checkout/mongo-connector/install_mc.sh

Here I pull a repository from github, then I copy a config.json to the folder I cloned the git repository. After that I need to run python setup.py install to install the package and then python setup.py install_service in the same directory.

I put both the installation commands in a shell file install_mc.sh and the copied the file to the same directory where I cloned the repository.

The git repository is cloned in /srv/checkout/mongo-connector/.

Following is the directory layout:

vagrant@vagrant-ubuntu-trusty-64:/srv/checkout/mongo-connector$ pwd
/srv/checkout/mongo-connector

vagrant@vagrant-ubuntu-trusty-64:/srv/checkout/mongo-connector$ ls
CHANGELOG.rst  config.json  ez_setup.py  install_mc.sh  LICENSE  mongo_connector  README.rst  scripts  setup.cfg  setup.py  tests

But then I run the ansible script using vagrant I get the followin error during the execution of install_mc.sh:

==> connector: TASK [Execute script] **********************************************************
==> connector: task path: /vagrant/provisioning/mc_playbook.yml:36
==> connector: fatal: [127.0.0.1]: FAILED! => {"changed": true, "failed": true, "rc": 2, "stderr": "chmod: cannot access ‘./setup.py’: No such file or directory\npython: can't open file './setup.py': [Errno 2] No such file or directory\npython: can't open file './setup.py': [Errno 2] No such file or directory\n", "stdout": "", "stdout_lines": []}
==> connector: 
==> connector: NO MORE HOSTS LEFT *************************************************************
==> connector:  to retry, use: --limit @mc_playbook.retry
==> connector: 
==> connector: PLAY RECAP *********************************************************************
==> connector: 127.0.0.1                  : ok=10   changed=4    unreachable=0    failed=1 

Content of install_mc.sh is:

#!/usr/bin/env bash

chmod +x ./setup.py
python ./setup.py install
python ./setup.py install_service

How should I correct this issue?

2 Answers
Related