cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1641
Views
0
Helpful
2
Replies

Ansible and Nexus Switch

AnthonyShahine
Level 1
Level 1

Dears,

Yesterday I wrote an ansible script in order to check the current traffic on an interface.

using crontab, the script run every 10 minutes.

everything was working fine, till today morning. where the ansible is still able to access the switch, but not able to get the data

 

below is my script:

---
- name: Get current Traffic
  hosts: switch
  gather_facts: false

  tasks:
    - name: show interface Eth1/46
      raw: "show interface Eth1/46 | inc input | inc output | inc rate"
    
      register: print_output

    -  debug: var=print_output.stdout_lines

    - name: save output to  file
      local_action: shell echo "{{ print_output.stdout_lines[0] }}" > /etc/ansible/showtraffic.txt

Knowing that the same script is still running fine with another nexus switch having the same version.

also, the ansible user is still able to access ssh the switch normally.

 

 

 

2 Replies 2

Seb Rupik
VIP Alumni
VIP Alumni

Hi there,

Try this playbook:

---
- name: Get current Traffic
  hosts: switch
  connection: network_cli
  gather_facts: no

  tasks:
    - name: show interface Eth1/46
      nxos_command:
        commands: show interface Eth1/46 | inc input | inc output | inc rate   
      register: print_output

    - name: debug_output
debug:
msg: {{print_output.stdout_lines}} - name: save output to file copy: content: "{{ print_output.stdout_lines[0] }}" dest: /etc/ansible/{{inventory_hostname}}_showtraffic.txt ...

cheers,

Seb.

I work on this issue for around 1 hour and i think the problem was related to the Nexus switch itself in addition that i was running the playbook from crontab ( every 15 min )

 

As by using show users, I found that the ansible user has a state of idle, and i was unable to kill his session with clear line vty-line.

 

So I disabled and re-enabled the ssh feature on Nexus. At this point  the session was killed.

Then I modified my ansible playbook in order to ensure than ansible user logout the nexus once the job is done.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: