cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
363
Views
0
Helpful
3
Replies

Ansible Wait for Ouput - ansible.builtin.wait_for module

Netmart
Level 1
Level 1

Hello,

I am working on a Metric check list including show commands.

Some of those commands provide output with a delay or even require to hit "enter" to scroll further down.

I was wondering, what the best approach would be to tackle this issue.

Not sure if the following module would be the proper approach:

ansible.builtin.wait_for module 

 

     - name: Task30 sh version  installed
       ios_command:
          commands:     
              - sh version installed

Thanks,

 

1 Accepted Solution

Accepted Solutions

Ok, I think I solved it by also changig the timeout.

Now, Ansible is waiting until command output and captures the whole output of " show version installed"

# Example – show version installed on Cisco Cat9k

---

- name: Ansible site-ios-xe-L2-L3-Metrics-Check-IDF_@M.Wolf_Jan2024

  hosts: MTIDFiosxe

  vars_files:

         - /home/wolfm/Ansible/vault_password.yml

  vars:

      ansible_become_pass: "{{ vault_sudo_password }}"

      ansible_python_interpreter: /usr/bin/python3

      ansible_command_timeout: 120

- name: Task30 sh version  installed

       ios_command:

          commands: sh version installed

          wait_for: result[0] contains Provisioning File

:

- name: Task30 sh version install install after upgrade

       debug:

          var: output30

View solution in original post

3 Replies 3

Ruben Cocheno
Spotlight
Spotlight

@Netmart 

Yes, an example

- name: Run show version and check to see if output contains IOS
  cisco.ios.ios_command:
    commands: show version
    wait_for: result[0] contains IOS

 

Tag me to follow up.
Please mark it as Helpful and/or Solution Accepted if that is the case. Thanks for making Engineering easy again.
Connect with me for more on Linkedin https://www.linkedin.com/in/rubencocheno/

Thank you Ruben.

There is one more challenge.

If show command requires to hit enter for "more".

For example "sh version installed" requires to hit more to scroll down.

 

Please advise.

Thanks.

Ok, I think I solved it by also changig the timeout.

Now, Ansible is waiting until command output and captures the whole output of " show version installed"

# Example – show version installed on Cisco Cat9k

---

- name: Ansible site-ios-xe-L2-L3-Metrics-Check-IDF_@M.Wolf_Jan2024

  hosts: MTIDFiosxe

  vars_files:

         - /home/wolfm/Ansible/vault_password.yml

  vars:

      ansible_become_pass: "{{ vault_sudo_password }}"

      ansible_python_interpreter: /usr/bin/python3

      ansible_command_timeout: 120

- name: Task30 sh version  installed

       ios_command:

          commands: sh version installed

          wait_for: result[0] contains Provisioning File

:

- name: Task30 sh version install install after upgrade

       debug:

          var: output30