@@ -38,6 +38,7 @@ This ensures stale objects are removed from NetBox keeping an accurate current s
38
38
* pyvmomi==7.0.3
39
39
* aiodns==2.0.0
40
40
* setuptools>=62.00.0
41
+ * pyyaml==6.0
41
42
42
43
### Environment
43
44
* NetBox >= 2.9
@@ -113,8 +114,8 @@ Run the containerized application in a kubernetes cluster
113
114
114
115
``` shell
115
116
docker build -t netbox-vsphere-sync .
116
- docker image tag netbox-vsphere-sync your-registry.host/netbox-vsphere-sync:v1.2.0
117
- docker image push your-registry.host/netbox-vsphere-sync:v1.2.0
117
+ docker image tag netbox-vsphere-sync your-registry.host/netbox-vsphere-sync:latest
118
+ docker image push your-registry.host/netbox-vsphere-sync:latest
118
119
119
120
kubectl create secret generic netbox-vsphere-sync --from-file=settings.ini
120
121
kubectl apply -f netbox-vsphere-sync-cronjob.yaml
@@ -132,20 +133,22 @@ A short description can be found [here](https://netbox.readthedocs.io/en/stable/
132
133
# Running the script
133
134
134
135
```
135
- usage: netbox-sync.py [-h] [-c settings.ini]
136
+ usage: netbox-sync.py [-h] [-c settings.ini [settings.ini ...]] [-g ]
136
137
[-l {DEBUG3,DEBUG2,DEBUG,INFO,WARNING,ERROR}] [-n] [-p]
137
138
138
139
Sync objects from various sources to NetBox
139
140
140
141
Version: 1.3.0 (2022-09-06)
141
142
Project URL: https://github.com/bb-ricardo/netbox-sync
142
143
143
- optional arguments :
144
+ options :
144
145
-h, --help show this help message and exit
145
- -c settings.ini, --config settings.ini
146
+ -c settings.ini [settings.ini ...] , --config settings.ini [settings.ini ...]
146
147
points to the config file to read config data from
147
148
which is not installed under the default path
148
149
'./settings.ini'
150
+ -g, --generate_config
151
+ generates default config file.
149
152
-l {DEBUG3,DEBUG2,DEBUG,INFO,WARNING,ERROR}, --log_level {DEBUG3,DEBUG2,DEBUG,INFO,WARNING,ERROR}
150
153
set log level (overrides config)
151
154
-n, --dry_run Operate as usual but don't change anything in NetBox.
@@ -160,9 +163,87 @@ optional arguments:
160
163
It is recommended to set log level to ` DEBUG2 ` this way the program should tell you what is happening and why.
161
164
Also use the dry run option ` -n ` at the beginning to avoid changes directly in NetBox.
162
165
163
- ## Setup
164
- Copy the [ settings-example.ini] ( https://github.com/bb-Ricardo/netbox-sync/blob/main/settings-example.ini ) sample settings file to ` settings.ini ` .
165
- All options are described in the example file.
166
+ ## Configuration
167
+ There are two ways to define configuration. Any combination of config file(s) and environment variables is possible.
168
+ * config files (the [ default config] ( https://github.com/bb-Ricardo/netbox-sync/blob/main/settings-example.ini ) file name is set to ` ./settings.ini ` .)
169
+ * environment variables
170
+
171
+ The config from the environment variables will have precedence over the config file definitions.
172
+
173
+ ### Config files
174
+ Following config file types are supported:
175
+ * ini
176
+ * yaml
177
+
178
+ There is also more than one config file permitted. Example (config file names are also just examples):
179
+ ``` bash
180
+ /opt/netbox-sync/netbox-sync.py -c common.ini all-sources.yaml additional-config.yaml
181
+ ```
182
+
183
+ All files are parsed in order of the definition and options will overwrite the same options if defined in a
184
+ previous config file.
185
+
186
+ To get config file examples which include descriptions and all default values, the ` -g ` can be used:
187
+ ``` bash
188
+ # this will create an ini example
189
+ /opt/netbox-sync/netbox-sync.py -g -c settings-example.ini
190
+
191
+ # and this will create an example config file in yaml format
192
+ /opt/netbox-sync/netbox-sync.py -g -c settings-example.yaml
193
+ ```
194
+
195
+ ### Environment variables
196
+ Each setting which can be defined in a config file can also be defined using an environment variable.
197
+
198
+ The prefix for all environment variables to be used in netbox-sync is: ` NBS `
199
+
200
+ For configuration in the ` common ` and ` netbox ` section a variable is defined like this
201
+ ```
202
+ <PREFIX>_<SECTION_NAME>_<CONFIG_OPTION_KEY>=value
203
+ ```
204
+
205
+ Following example represents the same configuration:
206
+ ``` yaml
207
+ # yaml config example
208
+ common :
209
+ log_level : DEBUG2
210
+ netbox :
211
+ host_fqdn : netbox-host.example.com
212
+ prune_enabled : true
213
+ ` ` `
214
+ ` ` ` bash
215
+ # this variable definition is equal to the yaml config sample above
216
+ NBS_COMMON_LOG_LEVEL="DEBUG2"
217
+ NBS_netbox_host_fqdn="netbox-host.example.com"
218
+ NBS_NETBOX_PRUNE_ENABLED="true"
219
+ ```
220
+
221
+ This way it is possible to expose for example the ` NBS_NETBOX_API_KEY ` only via an env variable.
222
+
223
+ The config definitions for ` sources ` need to be defined using an index. Following conditions apply:
224
+ * a single source needs to use the same index
225
+ * the index can be number or a name (but contain any special characters to support env var parsing)
226
+ * the source needs to be named with ` _NAME ` variable
227
+
228
+ Example of defining a source with config and environment variables.
229
+ ``` ini
230
+ ; example for a source
231
+ [source/example-vcenter]
232
+ enabled = True
233
+ type = vmware
234
+ host_fqdn = vcenter.example.com
235
+ username = vcenter-readonly
236
+ ```
237
+ ``` bash
238
+ # define the password on command line
239
+ # here we use '1' as index
240
+ NBS_SOURCE_1_NAME=" example-vcenter"
241
+ NBS_SOURCE_1_PASSWORD=" super-secret-and-not-saved-to-the-config-file"
242
+ NBS_SOURCE_1_custom_dns_servers=" 10.0.23.23, 10.0.42.42"
243
+ ```
244
+
245
+ Even to just define one source variable like ` NBS_SOURCE_1_PASSWORD ` the ` NBS_SOURCE_1_NAME ` needs to be defined as
246
+ to associate to the according source definition.
166
247
167
248
## Cron job
168
249
In Order to sync all items regularly you can add a cron job like this one
0 commit comments