大网数据广告活动
服务器运维问答

Invoking Python Script through Ansible Playbook and running it in background- Through Ansible Tower

· 52CE 我爱测

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 fini…

问题原文

原帖链接 · saffron · CC BY-SA 4.0

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.

已采纳解答

原帖链接 · Alexander Tolkachev · CC BY-SA 4.0

You should use Asynchronous Actions and Polling Ansible feature.

So your task should looks like:

- name: Long async task
  command: python data_pull_push.py
  async: <timeout value>
  poll: 0

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-04-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。