티스토리 뷰

ansible

cisco ansible config

fendys 2024. 4. 5. 20:59
반응형

nxis, ios 구분을 인벤토리에서 구분하여 when조건으로 실행 한다.

hosts - inventory

[network:children]
nxos
ios

[nxos]
nxos01 ansible_host=10.60.50.13

[nxos:vars]
ansible_connection=network_cli
ansible_network_os=nxos
ansible_user=fendys
ansible_password=password1!


[ios]
ios01 ansible_host=10.6.99.176
ios01 ansible_host=10.3.99.145

[ios:vars]
ansible_connection=network_cli
ansible_network_os=ios
ansible_user=fendys
ansible_password=password1!

#ansible_become=yes
#ansible_authorize=yes
#ansible_become_method=enable
#ansible_become_password=password2!

 

play-book - role type 

---
## fendys@tistory.com
## use : ansible-playbook network_work.yml --ask-vault-pass
- hosts: network
  gather_facts: false
  become: false

  roles:
    - { role : nxos, tags: ["reinstall"] }
    - { role : ios, tags: ["reinstall"] }

 

ios role - ios cli

## ansible/role/ios/tasks/main.yml
---
    - name: check ios version
      ios_command:
        commands: show version
      register: REGI_iosversion
      when: ansible_network_os == 'ios'

    - name: check ios running-config
      ios_command:
        commands: show running-config view full
      register: REGI_iosrun
      when: ansible_network_os == 'ios'

    - name: save version
      shell: echo "{{ REGI_iosversion.stdout  | join() }}" > /etc/ansible/result/network-config/$(date +'%Y-%m-%d')-{{ inventory_hostname }}-ios-version.log
      delegate_to: localhost
      when: ansible_network_os == 'ios'

    - name: save version
      shell: echo "{{ REGI_iosrun.stdout  | join() }}" > /etc/ansible/result/network-config/$(date +'%Y-%m-%d')-{{ inventory_hostname }}-ios-running-config.log
      delegate_to: localhost
      when: ansible_network_os == 'ios'

 

nxos role - nxos cli

---
    - name: check version
      nxos_command:
        commands: show version
      register: REGI_version
      when: ansible_network_os == 'nxos'

    - name: check nxos running-config
      nxos_command:
        commands: show running-config 
      register: REGI_run
      when: ansible_network_os == 'nxos'

    - name: save version
      shell: echo "{{ REGI_version.stdout  | join() }}" > /etc/ansible/result/network-config/$(date +'%Y-%m-%d')-{{ inventory_hostname | join() }}-nxos-version.log
      delegate_to: localhost
      when: ansible_network_os == 'nxos'
      
    - name: save username
      shell: echo "{{ REGI_run.stdout  | join() }}" > /etc/ansible/result/network-config/$(date +'%Y-%m-%d')-{{ inventory_hostname | join() }}-nxos-running-config.log
      delegate_to: localhost
      when: ansible_network_os == 'nxos'

 

 

반응형

'ansible' 카테고리의 다른 글

ansible remote shell  (0) 2023.08.31
cisco switch config backup  (0) 2022.02.28
install ansible on centos 7  (0) 2021.10.26
ansible 간단 명령어  (0) 2021.08.18
ansible key copy  (0) 2021.08.05