I am relatively knew to ansible and need a little assistance. We are trying to use ansible to backup our Cisco configuration. I figured that this would be fairly simple and I have made some progress but I am stuck at the moment.
I want to be able to run this playbook and have it output the configuration of the cisco router to a simple text file on the ansible server. The file name needs to be the current time when it ran in the format MMDDYYYY. I want to deposit the file in a folder that is the hostname of the switch defined in the inventory file.
I can get the playbook to run when I use the hostname for the file name and do not include the directory based on hostname, but the timestamp from the ansible server is failing due to the length of the filename being to long. Also the text of the configuration file is devoid of formatting so it is in a single line with quotation around each entry from the config. Here is a snippet from the file output:
{“changed”: false, “cisco.stdout_lines”: [[“Building configuration…”, “”, “Current configuration : 3389 bytes”, “!”, “version 12.2”, “no service pad”,
So the items I need help with are:
-
Format the show run so that we can use it for a copy paste restore at some point
-
Attach the local timestamp to the filename
-
Attach the hostname to the folder that the backup is placed
Running ansible 2.1.2
Here is my playbook so far (or what I thought would work)…