72 lines
2.2 KiB
Plaintext
72 lines
2.2 KiB
Plaintext
---
|
|
{%- from "netboxinventory/map.jinja" import netbox with context %}
|
|
netboxinventory-dependencies:
|
|
pkg.installed:
|
|
- name: dmidecode
|
|
|
|
netboxinventory-pip-dependencies:
|
|
pip.installed:
|
|
- name: pynetbox
|
|
|
|
{% set nodename = salt['grains.get']('nodename') %}
|
|
{% set location = salt['grains.get']('location') %}
|
|
{% set type = salt['grains.get']('type') %}
|
|
{% if salt['smbios.get']('system-manufacturer') %}
|
|
{% set manufacturer = salt['smbios.get']('system-manufacturer') %}
|
|
{% else %}{% set manufacturer = "none" %}{% endif %}
|
|
|
|
{% if salt['smbios.get']('system-manufacturer') %}
|
|
{% set model = salt['smbios.get']('system-product-name') %}
|
|
{% else %}{% set model = "none" %}{% endif %}
|
|
|
|
|
|
{%- if not salt['netbox.get'](app='dcim', endpoint='manufacturers', name=manufacturer) %}
|
|
netbox.create_manufacturer_{{ manufacturer|md5 }}:
|
|
module.run:
|
|
- name: netbox.create_manufacturer
|
|
- m_name: "{{ manufacturer }}"
|
|
{%- endif %}
|
|
|
|
{%- if not salt['netbox.get'](app='dcim', endpoint='device-types', model=model) %}
|
|
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 }}:
|
|
module.run:
|
|
- name: netbox.create_site
|
|
- site: "{{ location }}"
|
|
{%- endif %}
|
|
|
|
{%- if salt['netbox.get'](app='dcim', endpoint='device-roles', name=type) == {} %}
|
|
netbox.create_device_role_{{ type|md5 }}:
|
|
module.run:
|
|
- name: netbox.create_device_role
|
|
- role: "{{ type }}"
|
|
- color: "2196f3"
|
|
{%- endif %}
|
|
|
|
{%- if salt['netbox.get'](app='dcim', endpoint='devices', name=nodename) == {} %}
|
|
netbox.create_device_{{ nodename|md5 }}:
|
|
module.run:
|
|
- name: netbox.create_device
|
|
- 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 %}
|