07-03-2019 11:35 PM - edited 07-03-2019 11:37 PM
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.
07-04-2019 12:05 AM - edited 07-04-2019 12:57 AM
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.
07-04-2019 12:13 PM - edited 07-04-2019 12:22 PM
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.
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: