save router config with ansible

---- hosts: router  gather_facts: false  vars:    git_branch: /etc/ansible/playbooks/backuptasks:---- hosts: router  gather_facts: false  vars:    git_branch: /etc/ansible/playbooks/backuptasks:  - name: switch to target branch    command: git checkout "{{git_branch}}"    args:      chdir: {{ git_branch }}    changed_when: false  - name: Syncronize with remote branch    command: git pull origin master    args:      chdir: {{ git_branch }}    changed_when: false    delegate_to: localhost    run_once: yes  - name: Get Running Config    block:    - name: Get show running      ios_command:        commands: show running-config      register: ios_cmd    - name: copy Running config to backup folder      copy:        content: "{{ ios_cmd.stdout[0] }}"        dest: "/etc/ansible/playbooks/backup/router_bkup.txt"  - name: Check the directory status    command: git status    args:      chdir: {{ git_branch }}    register: changes    changed_when: false    delegate_to: localhost    run_once: yes  - name: Add files to Git staging area, commit and push    shell: |      git add .      git commit -m "Configuration Backup"      git push origin    args:      chdir: {{ git_branch }}    delegate_to: localhost    run_once: yes

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source