# Running ansible tasks in background and disown

**URL:** <https://forum.ansible.com/t/running-ansible-tasks-in-background-and-disown/30331>\
**Category:** Ansible Project\
**Created:** [May 15, 2019, 6:23am UTC](https://forum.ansible.com/t/running-ansible-tasks-in-background-and-disown/30331 "2019-05-15T06:23:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaustav\_Majumder](https://avatars.discourse-cdn.com/v4/letter/k/41988e/32.png) [@Kaustav\_Majumder](https://forum.ansible.com/u/Kaustav_Majumder)\
**Post date:** [May 15, 2019, 6:23am UTC](https://forum.ansible.com/t/running-ansible-tasks-in-background-and-disown/30331/1 "2019-05-15T06:23:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [May 15, 2019, 10:45am UTC](https://forum.ansible.com/t/running-ansible-tasks-in-background-and-disown/30331/2 "2019-05-15T10:45:59Z")

</div>

ansible facts can’t get the information?

---

<div class="post-metadata">

**Author:** ![Adam\_E](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Adam\_E](https://forum.ansible.com/u/Adam_E)\
**Post date:** [May 15, 2019, 11:14pm UTC](https://forum.ansible.com/t/running-ansible-tasks-in-background-and-disown/30331/3 "2019-05-15T23:14:38Z")

</div>

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…

```auto

- 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

```
