Expect still prompting to continue

29 views
Skip to first unread message

Andrew Okullu

unread,
Sep 26, 2022, 8:48:26 AM9/26/22
to ansible...@googlegroups.com
Dear Team
i have an issue. I have written a playbook that will perform and update of the netbackup java.
############################################################
Expect section
 
    - 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"
            exp_continue
            }

            }
################### Log waiting at prompt
spawn /usr/openv/netbackup/bin/goodies/nbcomponentupdate -product NetBackup -component jre -path /tmp/jdk1.8.0_341
Command line: /usr/openv/netbackup/bin/goodies/nbcomponentupdate -product NetBackup -component jre -path /tmp/jdk1.8.0_341

Java Runtime Envrionment(JRE) version installed with product 'Veritas NetBackup'                                 : 1.8.0_331 (64bit)
Java Runtime Envrionment(JRE) version found at path '/tmp/jdk1.8.0_341'                                          : 1.8.0_341 (64bit)

This utility will update the Java Runtime Envrionment(JRE) binaries present at '/usr/openv/java/jre' path

This utility may start and stop all (or some) services depending upon the present state of services.


Do you want to continue (Y[es]/N[o]):

From the log file its waiting at the prompt to continue the install.

Some guidance on where am going wrong.

Kind Regards
Andrew Okullu
| Skype:aokullu | twitter: @aokullu | gtalk: aokullu

Rowe, Walter P. (Fed)

unread,
Sep 26, 2022, 8:56:46 AM9/26/22
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

-- 
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CABcUpdpO7UkDCuCyGwZO3QEBUZWrmmZXsP6rVb_Ekqv%3DVJr9hg%40mail.gmail.com.

Rowe, Walter P. (Fed)

unread,
Sep 26, 2022, 8:58:40 AM9/26/22
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

Andrew Okullu

unread,
Sep 26, 2022, 9:05:01 AM9/26/22
to ansible...@googlegroups.com
Thanks @Walter. Let me try and revert.

Kind Regards
Andrew Okullu
| Skype:aokullu | twitter: @aokullu | gtalk: aokullu

Kevin Shumaker

unread,
Sep 26, 2022, 9:07:51 AM9/26/22
to Ansible Project
Is 'send "y\n" ' a valid response to the expect? Or should it be just "y" or just "n"?

Todd Lewis

unread,
Sep 26, 2022, 9:17:54 AM9/26/22
to Ansible Project
`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.

Kevin Shumaker

unread,
Sep 26, 2022, 9:22:32 AM9/26/22
to Ansible Project
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...

Rowe, Walter P. (Fed)

unread,
Sep 26, 2022, 9:40:13 AM9/26/22
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Alex Wanderley

unread,
Sep 26, 2022, 10:53:26 AM9/26/22
to ansible...@googlegroups.com
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.stdou
t"

Regards,

Alex

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.


--

 

Edmonton_sig_RGB_S.jpg

Alex Wanderley

Application and Infrastructure Analyst II
Storage and Backup Solutions

Financial and Corporate Services | Open City and Technology  

 

780-496-4156  Office

780-819-0273  Mobile

 

City of Edmonton

Century Place, 19th Floor

9803 102A Avenue NW

Edmonton AB, T5J 3A3

 

All information contained in this email post is proprietary to the City of Edmonton, confidential and intended only for the addressed recipient. If you have received this post in error, please disregard the contents, inform the sender of the misdirection, and remove it from your system. The copying, dissemination or distribution of this email, if misdirected, is strictly prohibited.


The contents of this message and any attachment(s) are confidential, proprietary to the City of Edmonton, and are intended only for the addressed recipient. If you have received this in error, please disregard the contents, inform the sender of the misdirection, and remove it from your system. The copying, dissemination, or distribution of this message, if misdirected, is strictly prohibited.

Andrew Okullu

unread,
Sep 29, 2022, 3:31:54 AM9/29/22
to ansible...@googlegroups.com
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.

Kind Regards
Andrew Okullu
| Skype:aokullu | twitter: @aokullu | gtalk: aokullu

Reply all
Reply to author
Forward
0 new messages