Here I am trying to invoke a python script through ansible playbook. When I run the playbook containing below mentioned code, it is successfully invoking the script. But ansible script continues to run till the Python script finishes all its Task.
- hosts: localhost
gather_facts: false
vars:
username: 'User'
password: '1234@345'
tasks:
- name: Invoking Python script
script: data_pull_push.py
args:
executable: python
The python script "data_pull_push.py" is getting data from a Url and posting it to another Url. It has too many data. So it takes really long time to retrieve and post all the data. So I want the Ansible playbook to trigger the Python script in it and close the playbook. Python script should be running in Background.
And this Ansible playbook and python script is kept in git and will be running the playbook in Ansible tower. I am not getting any idea how to use that in Ansible. If anyone knows Please let me know.
You should use Asynchronous Actions and Polling Ansible feature.
So your task should looks like:
Create a background job using your choice of job manager utilities like atd, cron, supervisord, or systemd. Merely examples, many other service managers exist depending on operating system.
Of these, at least cron, supervisord, and systemd have wrapper Ansible modules. Even if one doesn't exist, you can call systemd-run or whatever with a generic command.