Dear Team
i have an issue. I have written a playbook that will perform and update of the netbackup java.
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:
Regards,
Alex
Dear All,
Thanks alot for the pointers.
This is what I finally used to get it working.
Much appreciation for the pointers and guidance.