2

I have below task in my playbook, which generates lots of outputs on the screen. Is there a way to hide those lines (e.g. ok: [LAB_RT03] => (item=show runn) on-screen? Items in the file are list of show commands to run on network devices. In reality there will be 10's of commands.

The task

- name: "retrieve show commands  from Routers "
 ios_command:
   commands: 
   - command: "{{ item }}"
 loop: "{{ lookup('file', './commands/ios_commands.txt').splitlines() }}"
 register: ios_output
 ignore_errors: true
 when: ansible_network_os == 'ios'

Outputs:

ok: [LAB_RT03] => (item=show runn)
ok: [LAB_RT04] => (item=show runn)
ok: [LAB_RT04] => (item=show version)
ok: [LAB_RT03] => (item=show version)
ok: [LAB_RT04] => (item=show ip route vrf ext)
ok: [LAB_RT03] => (item=show ip route vrf ext)
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
har83
  • 33
  • 1
  • 8
  • 1
    if you could use `shell` over `command` then , replace `- command:"{{ item }}"` with `- shell: "{{ item }} &>/dev/null"` – P.... Jun 30 '21 at 02:51
  • I am not sure if [Adding Loop Controls](https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#adding-controls-to-loops) will provide you the expected result. You may just try. – U880D Jun 30 '21 at 18:42

1 Answers1

1

When you add your playbook loop control label 'LAB_RTO3' as following the example you can limit the displayed output.

- name: "retrieve show commands  from Routers "
 ios_command:
   commands: 
   - command: "{{ item }}"
 loop: "{{ lookup('file', './commands/ios_commands.txt').splitlines() }}"
 loop_control:
   label: "{{ LAB_RT03 }}"
 register: ios_output
 ignore_errors: true
 when: ansible_network_os == 'ios'
Baris Sonmez
  • 477
  • 2
  • 8