Expect still prompting to continue

Dear Team

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

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

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

Thanks @Walter. Let me try and revert.

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

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.

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…

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

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

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.