Skip to content

feat: device_type data provided as volume mount #935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ansible/playbooks/device_types_sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Device types sync
connection: local
hosts: nautobot
gather_facts: false

roles:
- role: device_types
10 changes: 10 additions & 0 deletions ansible/roles/device_types/tasks/console_ports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

- name: Create device type console port templates
networktocode.nautobot.console_port_template:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
device_type: "{{ device_type_item.model }}"
name: "{{ console_port_item.name }}"
type: "{{ console_port_item.type }}"
state: present
37 changes: 37 additions & 0 deletions ansible/roles/device_types/tasks/device_types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- name: Create default device types
networktocode.nautobot.device_type:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
model: "{{ device_type_item.model }}"
manufacturer: "{{ device_type_item.manufacturer }}"
u_height: "{{ device_type_item.u_height }}"
is_full_depth: "{{ device_type_item.is_full_depth }}"
part_number: "{{ device_type_item.part_number | default('') }}"
comments: "{{ device_type_item.comments | default('') }}"
subdevice_role: "parent" # need to set subdevice_role=parent to allow device bays to be attached
state: present

- name: Loop through interfaces and add them
ansible.builtin.include_tasks: interfaces.yml
loop: "{{ device_type_item.interfaces | default('[]') }}"
loop_control:
loop_var: interface_item

- name: Loop through console ports and add them
ansible.builtin.include_tasks: console_ports.yml
loop: "{{ device_type_item['console-ports'] | default('[]') }}"
loop_control:
loop_var: console_port_item

- name: Loop through module bays and add them
ansible.builtin.include_tasks: module_bays.yml
loop: "{{ device_type_item['module-bays'] | default('[]') }}"
loop_control:
loop_var: module_bay_item

- name: Loop through power ports and add them
ansible.builtin.include_tasks: power_ports.yml
loop: "{{ device_type_item['power-ports'] | default('[]') }}"
loop_control:
loop_var: power_port_item
11 changes: 11 additions & 0 deletions ansible/roles/device_types/tasks/interfaces.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

- name: Create device type interface templates
networktocode.nautobot.device_interface_template:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
device_type: "{{ device_type_item.model }}"
name: "{{ interface_item.name }}"
type: "{{ interface_item.type }}"
mgmt_only: "{{ interface_item.mgmt_only | default('false') }}"
state: present
34 changes: 34 additions & 0 deletions ansible/roles/device_types/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# Device Types repo: https://github.com/RSS-Engineering/undercloud-nautobot-device-types

- name: Check if device-types repo directory exists
ansible.builtin.stat:
path: /repo
register: repo_dir

- name: Fail if device-types repo directory is missing
ansible.builtin.fail:
msg: "/repo directory does not exist. Cannot proceed with device types sync."
when: not (repo_dir.stat.exists and repo_dir.stat.isdir)

- name: Collect device types from undercloud-nautobot-device-types repo
ansible.builtin.set_fact:
device_types_data: "{{ device_types_data | d([]) + [lookup('file', item.src) | from_yaml] }}"
with_community.general.filetree: "/repo/device-types/"
when: item.state == "file"
check_mode: false

- name: Sync manufacturers
networktocode.nautobot.manufacturer:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: "{{ item }}"
description: "{{ item }}"
state: present
loop: "{{ device_types_data | community.general.json_query('[*].manufacturer') | unique }}"

- name: Loop through device types
ansible.builtin.include_tasks: device_types.yml
loop: "{{ device_types_data }}"
loop_control:
loop_var: device_type_item
9 changes: 9 additions & 0 deletions ansible/roles/device_types/tasks/module_bays.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- name: Create device type module bay templates
networktocode.nautobot.device_bay_template:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
device_type: "{{ device_type_item.model }}"
name: "{{ module_bay_item.name }}"
state: present
12 changes: 12 additions & 0 deletions ansible/roles/device_types/tasks/power_ports.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---

- name: Create device type power port templates
networktocode.nautobot.power_port_template:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
device_type: "{{ device_type_item.model }}"
name: "{{ power_port_item.name }}"
allocated_draw: "{{ power_port_item.allocated_draw | default(1) }}"
maximum_draw: "{{ power_port_item.maximum_draw | default(1) }}"
type: "{{ power_port_item.type }}"
state: present
1 change: 1 addition & 0 deletions components/nautobot/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ resources:
- cloudnative-postgres-nautobot.yaml
- secretstore-nautobot.yaml
- external-secret-nautobot-sso.yaml
- device-sync-job.yaml

configMapGenerator:
- name: nautobot-sso
Expand Down