cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
717
Views
1
Helpful
7
Replies

AUTOMATIC BAKCUP OF CISCO DEVICES VIA ANSIBLE

felix.mugambi
Level 1
Level 1

Hello Team,

Hope you are all well.

I have this challenge when i try to run a playbook to back up network devices.

am attaching the playbook config and the error.

felixmugambi_0-1711351753754.png

- name: AUTOMATIC BACKUP OF RUNNING-CONFIG
hosts: Core_Switch
gather_facts: true
connection: local

 


tasks:
- name: DISPLAYING THE RUNNING-CONFIG
ios_command:
commands:
- show run
timeout: 30
host: "{{ ansible_host }}"
username: xxxxx
password: yyyyy
register: config

- name: Get Current Date
local_action: command date +%Y-%b-%d
register: date

- name: Get Current Time
local_action: command date +%H:%M
register: time

- name: save Output to /home/user1/Backups
copy:
content: "{{ config.stdout[0] }}"
dest: "/home/user1/Backups/_{{ date.stdout }}_at_{{ time.stdout }}-{{ inventory_hostname }}.txt"

Error is as below :- 

felixmugambi_1-1711351824517.png

 

7 Replies 7

You have connection: local, which is meant for tasks executed on the Ansible control machine itself.

Update the connection line to specify a connection type suitable for network devices.

connection: network_cli


I would also set the ansible_network_os variable to cisco.ios.ios to ensure Ansible uses the correct libraries.

 

 
Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

felixmugambi_0-1711354957981.png

Here the error am now getting.

Torbjørn
Spotlight
Spotlight

You seem to be missing the paramiko python module. It can be installed using pip, likely with the command "python3 -m pip install paramiko" depending on your OS.

Happy to help! Please mark as helpful/solution if applicable.
Get in touch: https://torbjorn.dev

felixmugambi_0-1711357605862.png

 

This could be one of two things based on the error incorrect credential and/or you are missing ansible-pylibssh library (pip install this)

Hope this helps.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Credentials are ok, since they can ssh to the device, Installed the library as well.

Anything else I might be missing?

 

can you run this with -vvvv and share the output, the only thing the last error is showing is the wrong creds, this will giev a more verbose output that might include additional details about the authentication failure in the error, also can you share the  inventory file too?

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Review Cisco Networking for a $25 gift card