Show Menu
Cheatography

Cisco-Ansible Cheat Sheet (DRAFT) by

Cheat sheet for backing up cisco devices with Ansible, and a few other commands for pushing configurations.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Ansible config­uration baseline

Ansible cfg:
[defaults]
invent­ory­=./­hosts
host_k­ey_­che­cki­ng=­False
retry_­fil­es_­ena­ble­d=False
gather­ing­=ex­plicit

backup playbook

---
- hosts: csr   tasks:           - name: Show version             ios_command:                     commands: show run             register: version           - name: print versions             copy:               content: "{{version.stdout[0]}}\n\r"               dest: ~/Cisco-ansible-backup/{{inventory_hostname}}-cfg.txt
The last section takes the results of 'show run' command and pastes it to the destin­ation folder.

ansibl­e-vault

ansible-vault encrypt group_vars/all.yml
 Please enter password: **
 Please enter password again: **
cat /group_vars/all.yml

$ANSIBLE_VAULT;1.1;AES256
38343566356634663036303038333735363735346166323936323861633039386234353737643266
6436373736333464616436653338386336373765663464340a316437396662353036663932393031
36383832333137323737323764613166306364623034633533386664373534336337616634336437
6362393832356337320a313161333830356338386561386665363637353838613565646666373164
61303661396364393437633636373138653466303539353334303963653232343432653766383835
63373261663335373834626433386538383734636430623139663638636633366133323766393366
38303362346264373766303466333431303762383031386265636364636538666563383234376638
33653239356635326636303431303431376563656631626463346639646639383431626165633562
31306139316432626338393561396361386330626261373366323930613166643839316536353832
62356365653439313638333865633738393863646363646336306331623535363739353132353732
35643032343330313136383431666335366165306335316537373536663839623233616561613034
66643335663733386533613466303763396132356534326661653666316230336561623436326664
34316337316164633661643836333038366530353238306633316266653862336532
Once encrypted, you will have to execute the playbook : ansibl­e-p­laybook backup.yml --ask-­vau­lt-pass
 

hosts file

hosts file
tiered hosts file
[csr]
csr1k-2 ansibl­e_h­ost­=19­2.1­68.2­55.38
csr1k-3 ansibl­e_h­ost­=19­2.1­68.2­55.34
 

all.yml

---
ansible_user: "cisco"
ansible_ssh_pass: "cisco"
ansible_network_os: "ios"
ansible_connection: "network_cli"
this file would be placed in group_vars folder in main directory. (see ansibl­e-vault section for encrypting this file for security reasons)