title: Installing a python package from source using ansible
body: <p>I have the following ansible playbook:</p>
  
  <pre><code>- 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
  </code></pre>
  
  <p>Here I pull a repository from github, then I copy a <code>config.json</code> to the folder I cloned the git repository. After that I need to run <code>python setup.py install</code> to install the package and then <code>python setup.py install_service</code> in the same directory.</p>
  
  <p>I put both the installation commands in a shell file <code>install_mc.sh</code> and the copied the file to the same directory where I cloned the repository.</p>
  
  <p>The git repository is cloned in <code>/srv/checkout/mongo-connector/</code>. </p>
  
  <p>Following is the directory layout:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>But then I run the ansible script using vagrant I get the followin error during the execution of <code>install_mc.sh</code>:</p>
  
  <pre><code>==&gt; connector: TASK [Execute script] **********************************************************
  ==&gt; connector: task path: /vagrant/provisioning/mc_playbook.yml:36
  ==&gt; connector: fatal: [127.0.0.1]: FAILED! =&gt; {"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": []}
  ==&gt; connector: 
  ==&gt; connector: NO MORE HOSTS LEFT *************************************************************
  ==&gt; connector:  to retry, use: --limit @mc_playbook.retry
  ==&gt; connector: 
  ==&gt; connector: PLAY RECAP *********************************************************************
  ==&gt; connector: 127.0.0.1                  : ok=10   changed=4    unreachable=0    failed=1 
  </code></pre>
  
  <p>Content of <code>install_mc.sh</code> is:</p>
  
  <pre><code>#!/usr/bin/env bash
  
  chmod +x ./setup.py
  python ./setup.py install
  python ./setup.py install_service
  </code></pre>
  
  <p>How should I correct this issue?</p>