Найти в Дзене
BecomeSysa

Настройка ansible сети для самых маленьких (часть 2)

Плейбук для получения данных с DNS сервера - hosts: localhost
gather_facts: no
become: yes
vars:
remove_strings: [has address]
tasks:
- name: create directory
file: path=/etc/ansible/tmp state=directory
- name: output RTR-HQ
command: "host rtr-hq"
register: rtrhq
- debug: var=rtrhq
- copy:
content: "{{ rtrhq.stdout | replace('\\n', '\n') }}"
dest: /etc/ansible/tmp/rtrhq.out
- replace:
path: /etc/ansible/tmp/rtrhq.out
regexp: '\b{{ item }}\b\s?'
replace: '- '
loop: "{{ remove_strings }}"
- name: output RTR-BR
command: "host rtr-br"
register: rtrbr
- debug: var=rtrbr
- copy:
content: "{{ rtrbr.stdout | replace('\\n', '\n') }}"
dest: /etc/ansible/tmp/rtrbr.out
- replace:
path: /etc/ansible/tmp/rtrbr.out
regexp: '\b{{ item }}\b\s?'
replace: '- '
loop: "{{ remove_strings }}"
- name: output SRV-HQ
command: "host srv-hq"
register: srvhq
- debug: var=srvhq

Плейбук для получения данных с DNS сервера

- hosts: localhost
gather_facts: no
become: yes
vars:
remove_strings: [has address]
tasks:
- name: create directory
file: path=/etc/ansible/tmp state=directory

- name: output RTR-HQ
command: "host rtr-hq"
register: rtrhq
- debug: var=rtrhq

- copy:
content: "{{ rtrhq.stdout | replace('\\n', '\n') }}"
dest: /etc/ansible/tmp/rtrhq.out

- replace:
path: /etc/ansible/tmp/rtrhq.out
regexp: '\b{{ item }}\b\s?'
replace: '- '
loop: "{{ remove_strings }}"


- name: output RTR-BR
command: "host rtr-br"
register: rtrbr
- debug: var=rtrbr

- copy:
content: "{{ rtrbr.stdout | replace('\\n', '\n') }}"
dest: /etc/ansible/tmp/rtrbr.out

- replace:
path: /etc/ansible/tmp/rtrbr.out
regexp: '\b{{ item }}\b\s?'
replace: '- '
loop: "{{ remove_strings }}"

- name: output SRV-HQ
command: "host srv-hq"
register: srvhq
- debug: var=srvhq

- copy:
content: "{{ srvhq.stdout | replace('\\n', '\n') }}"
dest: /etc/ansible/tmp/srvhq.out

- replace:
path: /etc/ansible/tmp/srvhq.out
regexp: '\b{{ item }}\b\s?'
replace: '- '
loop: "{{ remove_strings }}"

- name: output SRV-BR
command: "host srv-br"
register: srvbr
- debug: var=srvbr

- copy:
content: "{{ srvbr.stdout | replace('\\n', '\n') }}"
dest: /etc/ansible/tmp/srvbr.out

- replace:
path: /etc/ansible/tmp/srvbr.out
regexp: '\b{{ item }}\b\s?'
replace: '- '
loop: "{{ remove_strings }}"


- name: output CLI-HQ
command: "host cli-hq"
register: clihq
- debug: var=clihq

- copy:
content: "{{ clihq.stdout | replace('\\n', '\n') }}"
dest: /etc/ansible/tmp/clihq.out

- replace:
path: /etc/ansible/tmp/clihq.out
regexp: '\b{{ item }}\b\s?'
replace: '- '
loop: "{{ remove_strings }}"


- name: output CLI-BR
command: "host cli-br"
register: clibr
- debug: var=clibr

- copy:
content: "{{ clibr.stdout | replace('\\n', '\n') }}"
dest: /etc/ansible/tmp/clibr.out

- replace:
path: /etc/ansible/tmp/clibr.out
regexp: '\b{{ item }}\b\s?'
replace: '- '
loop: "{{ remove_strings }}"

- name: assemble
assemble:
src: /etc/ansible/tmp
dest: /etc/ansible/output.yaml

- name: delete garbage
file:
path: /etc/ansible/tmp
state: absent