# Issue on executing playbook using async options

**URL:** <https://forum.ansible.com/t/issue-on-executing-playbook-using-async-options/10582>\
**Category:** Get Help\
**Tags:** ssh, ansible, async\
**Created:** [October 29, 2024, 7:36pm UTC](https://forum.ansible.com/t/issue-on-executing-playbook-using-async-options/10582 "2024-10-29T19:36:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardobarbosams](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@ricardobarbosams](https://forum.ansible.com/u/ricardobarbosams)\
**Post date:** [October 29, 2024, 7:36pm UTC](https://forum.ansible.com/t/issue-on-executing-playbook-using-async-options/10582/1 "2024-10-29T19:36:16Z")

</div>

Hi everyone, I have a problem executing the following playbook

```yaml
- hosts:
    - server01
  gather_facts: no
  tasks:
  - name: task01
    command: bash /opt/script01.sh
    async: 86400 # 24 hours
    poll: 60 # checks every minute

```

Ansible version

```shell
# ansible --version
ansible [core 2.16.6]
  config file = /home/user01/ansible/ansible.cfg
  configured module search path = ['/home/user01/ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user01/ansible/.venv/lib/python3.10/site-packages/ansible
  ansible collection location = /home/user01/ansible/collections:/usr/share/ansible/collections
  executable location = /home/user01/ansible/.venv/bin/ansible
  python version = 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] (/home/user01/ansible/.venv/bin/python3)
  jinja version = 3.1.2
  libyaml = True

```

When the playbook runs it fails with the following message

```auto
ASYNC POLL on server01: jid=j99628350561.434557 started=1 finished=0
ASYNC POLL on server01: jid=j99628350561.434557 started=1 finished=0
ASYNC POLL on server01: jid=j99628350561.434557 started=1 finished=0
ASYNC POLL on server01: jid=j99628350561.434557 started=1 finished=0
ASYNC POLL on server01: jid=j99628350561.434557 started=1 finished=0
ASYNC POLL on server01: jid=j99628350561.434557 started=1 finished=0
ASYNC POLL on server01: jid=j99628350561.434557 started=1 finished=0
ASYNC FAILED on server01: jid=j99628350561.434557
fatal: [server01]: FAILED! => {"ansible_job_id": "j99628350561.434557", "changed": false, "finished": 1, "msg": "could not find job", "results_file": "/root/j99628350561.434557", "started": 1, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

PLAY RECAP *********************************************************************
server01 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0   

root@controller:~# 

```

I have configured ssh options in `/root/.ssh/config` file

```auto
Host *
  ControlMaster auto
  ControlPersist 86400 # 24hours

```

However, the ansible async directory exists on the target host.

```auto
# cat /root/.ansible_async/j99628350561.434557 | jq
{
    "changed": true,
    "stdout": "Oct 28 21:05:46 output command",
    "stderr": "",
    "rc": 0,
    "cmd": [
        "bash",
        "/opt/script01.sh"
    ],
    "start": "2024-10-28 21:05:46.085160",
    "end": "2024-10-29 07:00:25.368110",
    "delta": "9:54:39.282950",
    "msg": "",
    "invocation": {
        "module_args": {
            "_raw_params": "bash /opt/script01.sh",
            "_uses_shell": false,
            "expand_argument_vars": true,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "argv": null,
            "chdir": null,
            "executable": null,
            "creates": null,
            "removes": null,
            "stdin": null
        }
    }
}
#

```

Any idea what I’m doing wrong? let me know please.

Best regards

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [October 30, 2024, 10:05am UTC](https://forum.ansible.com/t/issue-on-executing-playbook-using-async-options/10582/2 "2024-10-30T10:05:28Z")

</div>

Welcome to the forum, @ricardobarbosams !

Based on this

> [@ricardobarbosams](#):
>
> `"msg": "could not find job", "results_file": "/root/j99628350561.434557"`

the async job should be `/root/j99628350561.434557`, and not

> [@ricardobarbosams](#):
>
> `# cat /root/.ansible_async/j99628350561.434557 `

Try explicitly setting the async directory in the playbook:

```yaml
---
- hosts: server01
  gather_facts: false
  vars:
    ansible_async_directory: "/tmp/.ansible_async"

  tasks:
      - name: Run script.
        ansible.builtin.command: "bash /opt/script01.sh"
        async: 86400 # 24 hours
        poll: 60 # checks every minute
```

---

<div class="post-metadata">

**Author:** ![ricardobarbosams](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@ricardobarbosams](https://forum.ansible.com/u/ricardobarbosams)\
**Post date:** [November 5, 2024, 9:05pm UTC](https://forum.ansible.com/t/issue-on-executing-playbook-using-async-options/10582/3 "2024-11-05T21:05:43Z")

</div>

It worked, Thank you very much 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 5, 2024, 9:06pm UTC](https://forum.ansible.com/t/issue-on-executing-playbook-using-async-options/10582/4 "2024-12-05T21:06:31Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
