updated netboxinventory state

This commit is contained in:
Paul 2023-01-04 23:37:24 +01:00
parent 6b4126f8d2
commit d5b1ed53ce

View File

@ -1,31 +1,61 @@
---
{%- from "netboxinventory/map.jinja" import netbox with context %}
netboxinventory_dependencies:
netboxinventory-dependencies:
pip.installed:
- name: pynetbox
{%- if salt['netbox.get'](app='dcim', endpoint='sites', name=salt['grains.get']('location')) == {} %}
netbox.create_site_{{ salt['grains.get']('location') }}:
{% set nodename = salt['grains.get']('nodename') %}
{% set location = salt['grains.get']('location') %}
{% set type = salt['grains.get']('type') %}
{% set manufacturer = salt['smbios.get']('system-manufacturer') %}
{% set model = salt['smbios.get']('system-product-name') %}
{%- if salt['netbox.get'](app='dcim', endpoint='manufacturers', name=manufacturer) == {} %}
netbox.create_manufacturer_{{ manufacturer|md5 }}:
module.run:
- name: netbox.create_site
- site: {{ salt['grains.get']('location') }}
- name: netbox.create_manufacturer
- m_name: "{{ manufacturer }}"
{%- endif %}
{%- if salt['netbox.get'](app='dcim', endpoint='device-roles', name=salt['grains.get']('type')) == {} %}
netbox.create_device_role_{{ salt['grains.get']('type') }}:
{%- if 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: {{ salt['grains.get']('type') }}
- role: "{{ type }}"
- color: "2196f3"
{%- endif %}
{%- if salt['netbox.get'](app='dcim', endpoint='devices', name=salt['grains.get']('nodename')) == {} %}
netbox.create_device_{{ salt['grains.get']('nodename')|to_camelcase }}:
{%- if salt['netbox.get'](app='dcim', endpoint='devices', name=nodename) == {} %}
netbox.create_device_{{ nodename|md5 }}:
module.run:
- name: netbox.create_device
- m_name: {{ salt['grains.get']('nodename') }}
- site: {{ salt['grains.get']('location') }}
- role: {{ salt['grains.get']('type') }}
- manufacturer: default
- model: default
- 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 %}