Running Python script via ansible
<p>I'm trying to run a python script from an ansible script. I would think this would be an easy thing to do, but I can't figure it out. I've got a project structure like this:</p>
<pre><code>playbook-folder
  roles
    stagecode
      files
        mypythonscript.py
      tasks
        main.yml
  release.yml
</code></pre>
<p>I'm trying to run mypythonscript.py within a task in main.yml (which is a role used in release.yml). Here's the task:</p>
<pre class="lang-yml prettyprint-override"><code>- name: run my script!
  command: ./roles/stagecode/files/mypythonscript.py
  args:
    chdir: /dir/to/be/run/in
  delegate_to: 127.0.0.1
  run_once: true
</code></pre>
<p>I've also tried ../files/mypythonscript.py. I thought the path for ansible would be relative to the playbook, but I guess not?</p>
<p>I also tried debugging to figure out where I am in the middle of the script, but no luck there either.</p>
<pre class="lang-yml prettyprint-override"><code>- name: figure out where we are
  stat: path=.
  delegate_to: 127.0.0.1
  run_once: true
  register: righthere
    
- name: print where we are
  debug: msg=&quot;{{righthere.stat.path}}&quot;
  delegate_to: 127.0.0.1
  run_once: true
</code></pre>
<p>That just prints out &quot;.&quot;. So helpful ...</p>