Adding Netbox
This commit is contained in:
9
roles/ansible-network.config_manager/tasks/edit.yaml
Normal file
9
roles/ansible-network.config_manager/tasks/edit.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: validate role spec
|
||||
validate_role_spec:
|
||||
spec: provider_spec.yaml
|
||||
|
||||
- name: invoke network provider
|
||||
include_role:
|
||||
name: "{{ ansible_network_provider }}"
|
||||
tasks_from: config_manager/edit
|
||||
9
roles/ansible-network.config_manager/tasks/get.yaml
Normal file
9
roles/ansible-network.config_manager/tasks/get.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: validate role spec
|
||||
validate_role_spec:
|
||||
spec: get_spec.yaml
|
||||
|
||||
- name: invoke network provider
|
||||
include_role:
|
||||
name: "{{ ansible_network_provider }}"
|
||||
tasks_from: config_manager/get
|
||||
74
roles/ansible-network.config_manager/tasks/load.yaml
Normal file
74
roles/ansible-network.config_manager/tasks/load.yaml
Normal file
@@ -0,0 +1,74 @@
|
||||
---
|
||||
- name: validate role spec
|
||||
validate_role_spec:
|
||||
spec: load_spec.yaml
|
||||
|
||||
# this block will clone the scm provided by config_manager_scm_url and either
|
||||
# discover the host configuration file or explicitly load a configuration file
|
||||
# defined by config_manager_scm_file.
|
||||
- name: retrieve configuration file from scm
|
||||
block:
|
||||
- name: create temp working directory
|
||||
tempfile:
|
||||
state: directory
|
||||
register: config_manager_working_dir
|
||||
changed_when: false
|
||||
|
||||
- name: checkout scm project
|
||||
git:
|
||||
repo: "{{ config_manager_scm_url }}"
|
||||
dest: "{{ config_manager_working_dir.path }}"
|
||||
changed_when: false
|
||||
|
||||
- name: discover the configuration file path and load it
|
||||
set_fact:
|
||||
config_manager_file: "{{ lookup('first_found', search_path) }}"
|
||||
vars:
|
||||
search_path:
|
||||
- "{{ config_manager_working_dir.path }}/{{ ansible_network_os }}/{{ inventory_hostname_short }}"
|
||||
- "{{ config_manager_working_dir.path }}/{{ ansible_network_os }}/{{ inventory_hostname_short }}.cfg"
|
||||
- "{{ config_manager_working_dir.path }}/{{ inventory_hostname_short }}"
|
||||
- "{{ config_manager_working_dir.path }}/{{ inventory_hostname_short }}.cfg"
|
||||
when: config_manager_scm_file is undefined
|
||||
|
||||
- name: set the config_manager_file value based on config_manager_scm_file
|
||||
set_fact:
|
||||
config_manager_file: "{{ config_manager_scm_file }}"
|
||||
when: config_manager_scm_file is defined
|
||||
|
||||
- name: remove temporary working dir
|
||||
file:
|
||||
path: config_manager_working_dir.path
|
||||
state: absent
|
||||
changed_when: false
|
||||
rescue:
|
||||
- name: remove temporary working dir
|
||||
file:
|
||||
path: "{{ config_manager_working_dir.path }}"
|
||||
state: absent
|
||||
changed_when: false
|
||||
|
||||
- name: fail the host
|
||||
fail:
|
||||
msg: "no configuration file found for host"
|
||||
when: config_manager_scm_url is defined
|
||||
|
||||
# if the configuration is provide via a file by setting config_manager_file
|
||||
# either explicitly or disovered via scm, load the configuration contents and
|
||||
# hand off config_manager_text to the provider role for implementation.
|
||||
- name: load config file contents
|
||||
set_fact:
|
||||
config_manager_text: "{{ lookup('config_template', config_manager_file) | join('\n') }}"
|
||||
when: config_manager_file is defined
|
||||
|
||||
# validate at this point that config_manager_text is set othewise fail
|
||||
# the host.
|
||||
- name: validate config_manager_text is defined
|
||||
fail:
|
||||
msg: "missing required arg: config_manager_text"
|
||||
when: config_manager_text is undefined
|
||||
|
||||
- name: invoke network provider
|
||||
include_role:
|
||||
name: "{{ ansible_network_provider }}"
|
||||
tasks_from: config_manager/load
|
||||
21
roles/ansible-network.config_manager/tasks/main.yml
Normal file
21
roles/ansible-network.config_manager/tasks/main.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
# tasks file for ansible-network.config_manager
|
||||
#
|
||||
- name: initialize function
|
||||
include_tasks: includes/init.yaml
|
||||
|
||||
- name: set role supported functions
|
||||
set_fact:
|
||||
config_manager_functions:
|
||||
- get
|
||||
- load
|
||||
- save
|
||||
- noop
|
||||
|
||||
- name: validate the requested function is supported
|
||||
fail:
|
||||
msg: "invalid function specified, expected one of {{ config_manager_functions }}, got {{ function }}"
|
||||
when: function | default('noop') not in config_manager_functions
|
||||
|
||||
- name: include function specific tasks and run
|
||||
include_tasks: "{{ function | default('noop') }}.yaml"
|
||||
4
roles/ansible-network.config_manager/tasks/noop.yaml
Normal file
4
roles/ansible-network.config_manager/tasks/noop.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
- name: display mesage
|
||||
debug:
|
||||
msg: "role version is {{ ansible_network_config_manager_version }}"
|
||||
9
roles/ansible-network.config_manager/tasks/save.yaml
Normal file
9
roles/ansible-network.config_manager/tasks/save.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: validate role spec
|
||||
validate_role_spec:
|
||||
spec: save_spec.yaml
|
||||
|
||||
- name: invoke network provider
|
||||
include_role:
|
||||
name: "{{ ansible_network_provider }}"
|
||||
tasks_from: config_manager/save
|
||||
Reference in New Issue
Block a user