[Ansible] NXOS의 running-config를 tftp로 자동으로 백업하기

[Ansible]  NXOS의 running-config를 tftp로 자동으로 백업하기
안녕하세요 원문을 그대로 옮겨 놓습니다 :) 
원문 작성자는 저라서 저작권 문제는 없을 것 같네요 ~!
https://sysnet4admin.blogspot.kr/2017/08/ansible-nxos-running-config-tftp.html#.WZobaiirQuU
===============================================

오늘 비 참 많이 오네요. 요즘 날씨는 동남아 날씨 같은....

아 주제는 이게 아니라...NXOS의 가장 중심이 되는 구성파일을 자동으로 tftp 서버로 백업해 보는 것을 할 예정입니다.


  

이건 이렇게 구동 됩니다.

CentOS7에 tftp 서버를 구축하고 여기서 앤서블 플레이북을 만들고 nxos switch 전송해서 백업을 다시 tftp 서버쪽으로 요청하는 겁니다.



CentOS에서 구성해 놓고 요청 보내서 (nxos)로 그리고 다시 그걸 centos로 받는거죠~!
(여기서 CentOS는 192.168.1.10이고 nxos의 mgmt0는 192.168.1.202입니다~!)

주의할 점이 몇가지 있는데..
1. /etc/ansible/hosts에 등록 되어 있어야함
2. 키 교환이 이루어진 상태여야 함
3. 여긴 고정이지만, 필요하다면 다이나믹하게 구성할수도 있음

주의할 점 적용 전에 실행하면 (호스트가 없어서 결과가 안 나옴)





 그 이후에 실행하면~!



결과 확인 
잘 백업된 NXOS의 Running-config ~!



[코드]
 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
- name: Setup tftp to backup NXOS running-config 

  hosts: localhost
  gather_facts: no
  tasks:
    - name: Install xinetd & tftp-server
      become: yes
      yum:
        name: "{{ item }}" 
        state: present
      with_items: 
        - "xinetd"
        - "tftp-server"
   
    - name: make tftp_shared_dirctory
      file:
        path: /home/vagrant/tftp_shared
        state: directory
        mode: 0777

    - name: modify tftp's config (1)
      become: yes
      replace:
         path: /etc/xinetd.d/tftp
         regexp: 'root'
         replace: 'vagrant'
        
    - name: modify tftp's config (2)
      become: yes
      replace:
         path: /etc/xinetd.d/tftp
         regexp: '-s /var/lib/tftpboot'
         replace: '-c -p -u vagrant -s /home/vagrant/tftp_shared'

    - name: modify tftp's config (3)
      become: yes
      lineinfile:
         path: /etc/xinetd.d/tftp
         regexp: 'disable'
         line: '        disable                 = disable'
 
    - name: modify tftp service's config
      become: yes
      replace:
         path: /usr/lib/systemd/system/tftp.service
         regexp: '-s /var/lib/tftpboot'
         replace: '-c -p -u vagrant -s /home/vagrant/tftp_shared'

    - name : selinux change to permissive 
      become: yes
      selinux: policy=targeted state=permissive
         
    - name : services deamon restart 
      become: yes
      systemd: 
        state: restarted
        daemon_reload: yes
        name: tftp

    - name : services restart 
      become: yes
      service :
        name : xinetd
        state : restarted
        
- name: Request to backup NXOS's running-config
  hosts: NXOS
  gather_facts: no
  connection: local
  tasks:
    - name: running-config backup
      nxos_command:
        commands: 'copy running-config tftp://192.168.1.10/n9k2-running-config vrf management'
        username: "admin"
        password: "vagrant"
        transport: cli

- name: selinux restore        
  hosts: localhost
  gather_facts: no
  tasks:
    - name : selinux change to enforcing
      become: yes
      selinux: policy=targeted state=enforcing

 
태그가 없습니다.

0개의 댓글이 있습니다.

댓글 남기기

댓글을 남기기 위해서는 로그인이 필요합니다.

로그인 회원가입