Removing Configuration for Individual Components
In the previous post, I demonstrated an example of a custom field. Inside the task, there was a state parameter. This parameter tells NetBox whether to create or delete it.
Leaving the state hard set inside the task means all custom tags (as in that example) will either be present, or absent in NetBox.
A neater way to do this is to add a state
item to the list so that each element of the list can be added or removed. I will demonstrate this with a tenant.
Playbook
0 1 2 3 4 5 6 7 8 9 |
--- - name: Playbook for configuring NetBox hosts: "localhost" collections: - netbox.netbox roles: - organisation |
Organisation Vars
The vars file contains the tenant_list
which is similar to the previous example of custom fields, but includes a state
. This will be for each tenant.
0 1 2 3 4 5 6 7 8 9 |
--- tenant_list: - data: name: Bank1 tenant_group: LPs custom_fields: bankfx_id: "SN123456789" state: present |
Organisation Tasks
Inside this task the state
parameter is present, and will use whatever is inside the tenant_list
0 1 2 3 4 5 6 7 8 9 10 |
--- - name: Create tenant within NetBox with only required information netbox.netbox.netbox_tenant: netbox_url: "{{ netbox_api_url }}" netbox_token: "{{ netbox_api_token }}" data: "{{ item.data }}" state: "{{ item.state }}" validate_certs: False loop: "{{ tenant_list }}" |