2020-07-10 00:58:55 +02:00
|
|
|
---
|
|
|
|
{%- from "netboxinventory/map.jinja" import netbox with context %}
|
2023-01-04 23:37:24 +01:00
|
|
|
netboxinventory-dependencies:
|
2023-02-10 13:54:33 +01:00
|
|
|
pkg.installed:
|
|
|
|
- name: dmidecode
|
|
|
|
|
|
|
|
netboxinventory-pip-dependencies:
|
2020-07-10 00:58:55 +02:00
|
|
|
pip.installed:
|
|
|
|
- name: pynetbox
|
|
|
|
|
2023-01-04 23:37:24 +01:00
|
|
|
{% set nodename = salt['grains.get']('nodename') %}
|
|
|
|
{% set location = salt['grains.get']('location') %}
|
|
|
|
{% set type = salt['grains.get']('type') %}
|
2023-01-20 13:24:50 +01:00
|
|
|
{% if salt['smbios.get']('system-manufacturer') %}
|
2023-01-04 23:37:24 +01:00
|
|
|
{% set manufacturer = salt['smbios.get']('system-manufacturer') %}
|
2023-01-20 13:24:50 +01:00
|
|
|
{% else %}{% set manufacturer = "none" %}{% endif %}
|
|
|
|
|
|
|
|
{% if salt['smbios.get']('system-manufacturer') %}
|
2023-01-04 23:37:24 +01:00
|
|
|
{% set model = salt['smbios.get']('system-product-name') %}
|
2023-01-20 13:24:50 +01:00
|
|
|
{% else %}{% set model = "none" %}{% endif %}
|
|
|
|
|
2023-01-04 23:37:24 +01:00
|
|
|
|
2023-01-20 13:24:50 +01:00
|
|
|
{%- if not salt['netbox.get'](app='dcim', endpoint='manufacturers', name=manufacturer) %}
|
2023-01-04 23:37:24 +01:00
|
|
|
netbox.create_manufacturer_{{ manufacturer|md5 }}:
|
|
|
|
module.run:
|
|
|
|
- name: netbox.create_manufacturer
|
|
|
|
- m_name: "{{ manufacturer }}"
|
|
|
|
{%- endif %}
|
|
|
|
|
2023-01-20 13:24:50 +01:00
|
|
|
{%- if not salt['netbox.get'](app='dcim', endpoint='device-types', model=model) %}
|
2023-01-04 23:37:24 +01:00
|
|
|
netbox.create_device_type_{{ model|md5 }}:
|
|
|
|
module.run:
|
|
|
|
- name: netbox.create_device_type
|
|
|
|
- model: "{{ model }}"
|
|
|
|
- manufacturer: "{{ manufacturer }}"
|
|
|
|
{%- endif %}
|
|
|
|
|
|
|
|
{%- if salt['netbox.get'](app='dcim', endpoint='sites', name=location) == {} %}
|
|
|
|
netbox.create_site_{{ salt['grains.get']('location')|md5 }}:
|
2020-07-10 00:58:55 +02:00
|
|
|
module.run:
|
|
|
|
- name: netbox.create_site
|
2023-01-04 23:37:24 +01:00
|
|
|
- site: "{{ location }}"
|
2020-07-10 00:58:55 +02:00
|
|
|
{%- endif %}
|
|
|
|
|
2023-01-04 23:37:24 +01:00
|
|
|
{%- if salt['netbox.get'](app='dcim', endpoint='device-roles', name=type) == {} %}
|
|
|
|
netbox.create_device_role_{{ type|md5 }}:
|
2020-07-10 00:58:55 +02:00
|
|
|
module.run:
|
|
|
|
- name: netbox.create_device_role
|
2023-01-04 23:37:24 +01:00
|
|
|
- role: "{{ type }}"
|
2020-07-10 00:58:55 +02:00
|
|
|
- color: "2196f3"
|
|
|
|
{%- endif %}
|
|
|
|
|
2023-01-04 23:37:24 +01:00
|
|
|
{%- if salt['netbox.get'](app='dcim', endpoint='devices', name=nodename) == {} %}
|
|
|
|
netbox.create_device_{{ nodename|md5 }}:
|
2020-07-10 00:58:55 +02:00
|
|
|
module.run:
|
|
|
|
- name: netbox.create_device
|
2023-01-04 23:37:24 +01:00
|
|
|
- m_name: "{{ nodename }}"
|
|
|
|
- site: "{{ location }}"
|
|
|
|
- role: "{{ type }}"
|
|
|
|
- manufacturer: "{{ manufacturer }}"
|
|
|
|
- model: "{{ model }}"
|
|
|
|
{%- else %}
|
|
|
|
netbox.update_device_{{ nodename|md5 }}:
|
|
|
|
module.run:
|
|
|
|
- name: netbox.update_device
|
|
|
|
- m_name: "{{ nodename }}"
|
|
|
|
- site: "{{ location }}"
|
|
|
|
- role: "{{ type }}"
|
|
|
|
- manufacturer: "{{ manufacturer }}"
|
|
|
|
- model: "{{ model }}"
|
|
|
|
{%- endif %}
|