title: How can I run an ansible play programmatically while still using a local file as my play?
body: <h1>Setup/Contraints</h1>
  
  <p>I want to run an ansible play located at /tmp/run_tests.yml and I want to perform the run in a python script, not command line (these are general constraints on the problem I am working on). I;ve tried several different approaches which all feel like guess work on reverse engineering the Runner class but have been unsuccessful. I was hoping to find out if this is possible and what the code would look like.  </p>
  
  <p>If I want to run a single command I can simply use the Ansible API's runner:</p>
  
  <h2>works.py (a simple example of using the Runner with a module)</h2>
  
  <pre><code>ansible.runner.Runner(**{
              "pattern": '*',
              "module_name": 'ping',
              "inventory": webInventory,
              "remote_user": self.username,
              "private_key_file": self.private_key
          }).run() 
  </code></pre>
  
  <h2>doesnotwork.py (trying to use runner with a play)</h2>
  
  <pre><code>hosts = ["127.0.0.0.1"] #dummy ip address
  webInventory = ansible.inventory.Inventory(hosts)
  
  runner = ansible.runner.Runner(pattern="*", )
  response = runner.run(**{
      "pattern": '*',
      "module_name": "/tmp/run_tests.yml",
      "inventory": webInventory,
      "remote_user": "ubuntu",
      "private_key_file": "~/.ssh/id_rsa"
  })
  </code></pre>
  
  <h2>Error Produced</h2>
  
  <pre><code>{'contacted': {}, 'dark': {'127.0.0.1': {'failed': True, 'msg': 'module is missing interpreter line'}}}
  </code></pre>
  
  <p>From the source, the error suggests a shebang is missing and since I am new to ansible I speculate passing a yml file is not an appropriate file for a module_name. What would the runner command have to look like in order to run my python play?</p>