Running ansible tasks in background and disown

Hi all, i am trying to top , sar , iostats in the backgound via ansible on remote hosts and collect stats redirecting outpu to a log file while I run other tasks from my local machine. I have tried - name: collect hypervisor stats hosts: all tasks: - name: execute sar iostat scripts shell: top -bd $MON_INTERVAL > $GLUSTER_PROFILER_RESULTS/top_proc.$HOSTNAME.txt & disown but it stops by itself. I want to kill the tasks after sometime manually. Is there any way

ansible facts can’t get the information?

not sure if you would get different results, but maybe try nohup instead of disown. ie.- name: execute sar iostat scripts shell: nohup top -bd $MON_INTERVAL > $GLUSTER_PROFILER_RESULTS/top_proc.$HOSTNAME.txt &

Another option could be to use the “at” module to schedule a task to start immediately. ie…


- name: Schedule a command to execute in 0 minutes as root.
  at:
    command: top -bd $MON_INTERVAL > $GLUSTER_PROFILER_RESULTS/top_proc.$HOSTNAME.txt 
    count: 0
    units: minutes