Adding Netbox

This commit is contained in:
Patrick Toal
2019-05-06 00:34:45 -04:00
parent 832502de34
commit 6e2205a046
278 changed files with 12767 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
---
- name: validate ios_config_text is defined
fail:
msg: "missing required arg: ios_config_text"
when: ios_config_text is undefined
- name: set the ios_config_temp_file name
set_fact:
ios_config_temp_file: "tmp_ansible"
- name: create temp working dir
tempfile:
state: directory
register: ios_config_temp_dir
- name: write the config text to disk
copy:
content: "{{ ios_config_text }}"
dest: "{{ ios_config_temp_dir.path }}/{{ ios_config_temp_file }}"
- name: get current list of files on remote device
cli:
command: dir
register: ios_dir_listing
- name: remove temporary files from target device
cli:
command: "delete /force flash:/{{ ios_config_temp_file }}"
when: ios_config_temp_file in ios_dir_listing.stdout
- name: enable the ios scp server
cli:
command: "{{ line }}"
loop:
- configure terminal
- ip scp server enable
- end
loop_control:
loop_var: line
- name: copy configuration to device
net_put:
src: "{{ ios_config_temp_dir.path }}/{{ ios_config_temp_file }}"
dest: "flash:/{{ ios_config_temp_file }}"
changed_when: false
- name: merge with current active configuration
cli:
command: "{{ line }}"
loop:
- "copy flash:/{{ ios_config_temp_file }} force"
- "delete /force flash:/{{ ios_config_temp_file }}"
loop_control:
loop_var: line
- name: remove local temp working dir
file:
path: "{{ ios_config_temp_dir.path }}"
state: absent

View File

@@ -0,0 +1,59 @@
---
- name: validate ios_config_text is defined
fail:
msg: "missing required arg: ios_config_text"
when: ios_config_text is undefined
- name: set the ios_config_temp_file name
set_fact:
ios_config_temp_file: "tmp_ansible"
- name: create temp working dir
tempfile:
state: directory
register: ios_config_temp_dir
- name: write the config text to disk
copy:
content: "{{ ios_config_text }}"
dest: "{{ ios_config_temp_dir.path }}/{{ ios_config_temp_file }}"
- name: get current list of files on remote device
cli:
command: dir
register: ios_dir_listing
- name: remove temporary files from target device
cli:
command: "delete /force flash:/{{ ios_config_temp_file }}"
when: ios_config_temp_file in ios_dir_listing.stdout and ios_config_remove_temp_files
- name: enable the ios scp server
cli:
command: "{{ line }}"
loop:
- configure terminal
- ip scp server enable
- end
loop_control:
loop_var: line
- name: copy configuration to device
net_put:
src: "{{ ios_config_temp_dir.path }}/{{ ios_config_temp_file }}"
dest: "flash:/{{ ios_config_temp_file }}"
changed_when: false
- name: replace current active configuration
cli:
command: "{{ line }}"
loop:
- "config replace flash:/{{ ios_config_temp_file }} force"
- "delete /force flash:/{{ ios_config_temp_file }}"
loop_control:
loop_var: line
- name: remove local temp working dir
file:
path: "{{ ios_config_temp_dir.path }}"
state: absent

View File

@@ -0,0 +1,41 @@
---
# this block is responsible for loading the configuration on to the target
# device line by line from config model.
- name: load configuration onto target device
block:
- name: load configuration lines into target device
block:
- name: extract banners from configs if present
extract_banners:
config: "{{ ios_config_text }}"
register: result
- name: load configuration lines into target device except banner
cli_config:
config: "{{ result['config'] }}"
register: ios_config_output
- name: enter configuration mode
cli:
command: "configure terminal"
- name: load banner lines into target device
cli_command:
command: "{{ item }}"
sendonly: true
with_items: "{{ result['banners'] }}"
register: banner_config_output
- name: exit configuration mode
cli:
command: end
rescue:
- name: exit configuration mode
cli:
command: end
- name: set host failed
fail:
msg: "error loading configuration lines"
when: not ansible_check_mode