# Expect still prompting to continue

**URL:** <https://forum.ansible.com/t/expect-still-prompting-to-continue/37143>\
**Category:** Ansible Project\
**Created:** [September 26, 2022, 12:47pm UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143 "2022-09-26T12:47:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aokullu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/aokullu/32/458_2.png) [@aokullu](https://forum.ansible.com/u/aokullu)\
**Post date:** [September 26, 2022, 12:47pm UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143/1 "2022-09-26T12:47:40Z")

</div>

Dear Team

i have an issue. I have written a playbook that will perform and update of the netbackup java.

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [September 26, 2022, 12:56pm UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143/2 "2022-09-26T12:56:29Z")

</div>

Here is an example of using expect from the ansible-doc shell output.

> # You can use shell to run other executables to perform actions inline
> 
> - name: Run expect to wait for a successful PXE boot via out-of-band CIMC  
> ansible.builtin.shell: |  
> set timeout 300  
> spawn ssh admin@{{ cimc\_host }}
> 
> expect “password:”  
> send “{{ cimc\_password }}\n”
> 
> expect “\n{{ cimc\_name }}”  
> send “connect host\n”
> 
> expect “pxeboot.n12”  
> send “\n”
> 
> exit 0  
> args:  
> executable: /usr/bin/expect  
> delegate\_to: localhost

In your case you might need to change it to look like this:

> - name: Install  
> shell: |  
> set timeout -1  
> log\_file /tmp/nbexpect.log  
> spawn /usr/openv/netbackup/bin/goodies/nbcomponentupdate -product NetBackup -component jre -path /tmp/jdk1.8.0\_341  
> expect “Do you wish to continue”

> sleep 1

> send “y\n”

I have not done this myself. This is just a guess based on the ansible-doc page for the shell module.

Walter

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [September 26, 2022, 12:58pm UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143/3 "2022-09-26T12:58:24Z")

</div>

Also note they specifically tell the shell module that expect is the executable. See **blue bold** text below.

> > - name: Run expect to wait for a successful PXE boot via out-of-band CIMC  
> > ansible.builtin.shell: |  
> > set timeout 300  
> > spawn ssh admin@{{ cimc\_host }}
> > 
> > expect “password:”  
> > send “{{ cimc\_password }}\n”
> > 
> > expect “\n{{ cimc\_name }}”  
> > send “connect host\n”
> > 
> > expect “pxeboot.n12”  
> > send “\n”
> > 
> > exit 0  
> > **args:**  
> > **executable: /usr/bin/expect**  
> > delegate\_to: localhost

Walter

---

<div class="post-metadata">

**Author:** ![aokullu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/aokullu/32/458_2.png) [@aokullu](https://forum.ansible.com/u/aokullu)\
**Post date:** [September 26, 2022, 1:04pm UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143/4 "2022-09-26T13:04:10Z")

</div>

Thanks @Walter. Let me try and revert.

---

<div class="post-metadata">

**Author:** ![Kevin\_Shumaker](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@Kevin\_Shumaker](https://forum.ansible.com/u/Kevin_Shumaker)\
**Post date:** [September 26, 2022, 1:07pm UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143/5 "2022-09-26T13:07:51Z")

</div>

Is 'send “y\n” ’ a valid response to the expect? Or should it be just “y” or just “n”?

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 26, 2022, 1:17pm UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143/6 "2022-09-26T13:17:54Z")

</div>

`send "y\n"` is a “y” followed by a new-line character, which may work (I would be surprised), but most of the ‘expect’ examples I’m seeing would use `send "y\r"` which is a “y” followed by a return.

---

<div class="post-metadata">

**Author:** ![Kevin\_Shumaker](https://avatars.discourse-cdn.com/v4/letter/k/eb9ed0/32.png) [@Kevin\_Shumaker](https://forum.ansible.com/u/Kevin_Shumaker)\
**Post date:** [September 26, 2022, 1:22pm UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143/7 "2022-09-26T13:22:32Z")

</div>

In my non-ansible scripts, I just sent the ‘y’ or the ‘n’ ans the request isn’t for a “y[enter]” and they (the apps) can get confused when the see something other than what they want…

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [September 26, 2022, 1:39pm UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143/8 "2022-09-26T13:39:55Z")

</div>

The ansible-doc page for ansible.builtin.shell shows it including the newline [enter].

> # You can use shell to run other executables to perform actions inline
> 
> - name: Run expect to wait for a successful PXE boot via out-of-band CIMC  
> ansible.builtin.shell: |  
> set timeout 300  
> spawn ssh admin@{{ cimc\_host }}
> 
> expect “password:”  
> send “{{ cimc\_password }} **\n** ”
> 
> expect “\n{{ cimc\_name }}”  
> send “connect host\*\*\n\*\*”
> 
> expect “pxeboot.n12”  
> send “ **\n** ”
> 
> exit 0  
> args:  
> executable: /usr/bin/expect  
> delegate\_to: localhost

Walter

---

<div class="post-metadata">

**Author:** ![Alex\_Wanderley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/alex_wanderley/32/3232_2.png) [@Alex\_Wanderley](https://forum.ansible.com/u/Alex_Wanderley)\
**Post date:** [September 26, 2022, 2:52pm UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143/9 "2022-09-26T14:52:59Z")

</div>

Hello Andrew,

Why not use Ansible’s “expect” module instead?  
I’ve been using it in a playbook to perform an interactive installation and that module works just fine as the expect Shell command:

- name: install ahf  
expect:  
echo: yes  
timeout: null  
command: “{{ ahf\_installer }}”  
responses:  
(._)Do you want to install AHF at [/opt/oracle.ahf] ? [Y]|N :(._): “Y”  
(._)Please Enter AHF Data Directory :(._): “{{ server\_data\_dir }}”  
(._)Do you want to add AHF Notification Email IDs ? [Y]|N :(._): “N”  
(._)Enter Email IDs separated by space :(._): “{{ ahf\_notification\_emails }}”  
(._)Do you want AHF to store your My Oracle Support Credentials for Automatic Upload ? Y|[N] :(._): “N”  
register: ahf\_installer\_result  
changed\_when: “‘AHF is already installed’ not in ahf\_installer\_result.stdout”

Regards,

Alex

---

<div class="post-metadata">

**Author:** ![aokullu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/aokullu/32/458_2.png) [@aokullu](https://forum.ansible.com/u/aokullu)\
**Post date:** [September 29, 2022, 7:31am UTC](https://forum.ansible.com/t/expect-still-prompting-to-continue/37143/10 "2022-09-29T07:31:05Z")

</div>

Dear All,  
Thanks alot for the pointers.  
This is what I finally used to get it working.

- name: Install Java update for Netbackup  
shell: |  
set timeout 300  
spawn /usr/openv/netbackup/bin/goodies/nbcomponentupdate -product NetBackup -component jre -path /tmp/jdk1.8.0\_341  
expect "Do you want to continue "  
send “y\r”  
interact  
exit 0  
args:  
executable: /usr/bin/expect

Much appreciation for the pointers and guidance.
