cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Ask the Expert- SD-WAN

136
Views
0
Helpful
2
Replies
Highlighted
Beginner

Ansible and Nexus Switch

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.

 

 

 

Everyone's tags (2)
2 REPLIES 2
VIP Advisor

Re: Ansible and Nexus Switch

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.

Beginner

Re: Ansible and Nexus Switch

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.

CreatePlease to create content
Content for Community-Ad
July's Community Spotlight Awards