# Async and expect module

**URL:** <https://forum.ansible.com/t/async-and-expect-module/21139>\
**Category:** Ansible Project\
**Created:** [April 12, 2016, 2:08pm UTC](https://forum.ansible.com/t/async-and-expect-module/21139 "2016-04-12T14:08:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Gonzalez\_Marti](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@David\_Gonzalez\_Marti](https://forum.ansible.com/u/David_Gonzalez_Marti)\
**Post date:** [April 12, 2016, 2:08pm UTC](https://forum.ansible.com/t/async-and-expect-module/21139/1 "2016-04-12T14:08:35Z")

</div>

I’m trying to use expect Ansible module to perform an interactive task in a virtual machine. The module works, but the task is very long and I have problems with the timeout. I get an error like this. I tried to use async but it fails and returns this error:

[0;32m qemu: fatal: [deploy]: FAILED! =\> {“changed”: false, “failed”: true, “invocation”: {“module\_args”: {“async”: 600, “command”: “config\_exec”, “poll”: 300, “responses”: {“(?i)continue”: “y”, “(?i)password”: “pass”}}, “module\_name”: “expect”}, “msg”: “unsupported parameter for module: async”}

This is the part of my playbook with problems:

# Configure system for user

- hosts: deploy  
tasks:
- shell: whoami  
register: result
- debug: var=result
- name: configuration  
expect:  
command: config\_exec  
responses:  
(?i)password: “{{pass}}”  
(?i)continue: “y”  
async: 600  
poll: 300

Is there any way to make expect and async to work together?

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [April 12, 2016, 6:58pm UTC](https://forum.ansible.com/t/async-and-expect-module/21139/2 "2016-04-12T18:58:16Z")

</div>

You need to outdent async/poll args- those are task args, not module args (so they need to line up with name and “expect”).

---

<div class="post-metadata">

**Author:** ![David\_Gonzalez\_Marti](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@David\_Gonzalez\_Marti](https://forum.ansible.com/u/David_Gonzalez_Marti)\
**Post date:** [April 14, 2016, 8:34am UTC](https://forum.ansible.com/t/async-and-expect-module/21139/3 "2016-04-14T08:34:33Z")

</div>

I outdented async and poll and now it complains about syntax. In Ansible documentation is aligned with the command, not the task.

---

<div class="post-metadata">

**Author:** ![David\_Gonzalez\_Marti](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@David\_Gonzalez\_Marti](https://forum.ansible.com/u/David_Gonzalez_Marti)\
**Post date:** [April 22, 2016, 12:34pm UTC](https://forum.ansible.com/t/async-and-expect-module/21139/4 "2016-04-22T12:34:37Z")

</div>

Finally I was able to make it work without async. Using the parameter timeout in expect module. It seems that expect keeps waiting for the input even if there is no need and I had to add the timeout to let the command run without problems.
