Skip to content

Commit 6c59753

Browse files
committed
allow branch specific alues for all bootstrap models
1 parent cdb9893 commit 6c59753

File tree

7 files changed

+164
-18
lines changed

7 files changed

+164
-18
lines changed

changes/1030.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added ability to manage branch specific values for models in Bootstrap integration.

docs/user/integrations/bootstrap.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,32 @@ external_integration:
160160
- "9876"
161161
```
162162
163+
### Branch Specific Values
164+
If you are running multiple Nautobot environments, some values may need to be specific to the Nautobot environment. For example in `development` you might want all GitRepository objects to use the branch `develop`. Also for ScheduledJobs you might need to send specific UUID values as `job_vars`, which are unique to each Nautobot environment. You can create these 'branch values' that are specific to each object type. You will want to update your `PLUGINS_CONFIG` in `nautobot_config.py` to include the value you wish to use for the Branch Values File.
165+
166+
```python
167+
PLUGINS_CONFIG = {
168+
"nautobot_ssot": {
169+
"bootstrap_nautobot_environment_branch": os.getenv("NAUTOBOT_BOOTSTRAP_SSOT_ENVIRONMENT_BRANCH", "develop"),
170+
}
171+
}
172+
```
173+
174+
Then create a YAML file in the same format as `global_settings.py`, to 'override' any specific object found in the Global Settings. If you wish to use a specific value for ALL object types, simply add an object with the `name` set to `default`, and it will take effect for all objects of that type that have a blank or missing value for that setting. If the object is already assigned a value, that value will take precedence over this default setting.
175+
163176
#### develop.yml
164177

165178
```yaml
166-
git_branch: develop
179+
---
180+
git_repository: # Sets all git_repositories to this branch (if unspecified in global_settings)
181+
- name: "default"
182+
branch: "develop"
183+
# git_branch: "develop" # this method has been deprecated, use above method
184+
scheduled_job:
185+
- name: "Test Scheduled Job" # Add job_vars with unique UUID's to a specific Job
186+
job_vars:
187+
integration: 1234567890
188+
tenant: 987765412
167189
```
168190

169191
## Content Types

nautobot_ssot/integrations/bootstrap/diffsync/adapters/bootstrap.py

Lines changed: 116 additions & 10 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
---
2-
git_branch: "develop"
2+
git_repository:
3+
- name: "default"
4+
branch: "develop"
5+
# git_branch: "develop" # this method has been deprecated, use above method
6+
scheduled_job:
7+
- name: "Test Scheduled Job"
8+
job_vars:
9+
integration: 1234567890
10+
tenant: 987765412

nautobot_ssot/integrations/bootstrap/fixtures/global_settings.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ software_image:
597597
image_file_checksum: ""
598598
hashing_algorithm: "SHA256"
599599
default_image: false
600-
device_types: ["arista-switch"]
600+
device_types: []
601601
tags: ["Test"]
602602
- software: "paloalto_panos - 11.0.3"
603603
status: "Active"
@@ -836,7 +836,7 @@ prefix:
836836
scheduled_job:
837837
- name: "Test Scheduled Job"
838838
interval: "daily"
839-
start_time: "2025-01-28T23:00:00+00:00"
839+
start_time: "2025-12-28 23:00:00+00:00"
840840
job_model: "Export Object List"
841841
user: "admin"
842842
custom_field:

nautobot_ssot/tests/bootstrap/fixtures/global_settings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,11 @@
870870
"user": "admin",
871871
"interval": "daily",
872872
"crontab": "",
873-
"start_time": "2025-01-28T23:00:00+00:00",
874-
"job_vars": {}
873+
"start_time": "2025-12-28T23:00:00+00:00",
874+
"job_vars": {
875+
"integration": 1234567890,
876+
"tenant": 987765412
877+
}
875878
}
876879
],
877880
"software_version": [

nautobot_ssot/tests/bootstrap/test_bootstrap_setup.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,10 @@ def _setup_git_repositories(self):
931931
for _repo in GLOBAL_YAML_SETTINGS["git_repository"]:
932932
if _repo.get("branch"):
933933
_git_branch = _repo["branch"]
934-
else:
934+
elif DEVELOP_YAML_SETTINGS.get("git_branch"):
935935
_git_branch = DEVELOP_YAML_SETTINGS["git_branch"]
936+
else:
937+
_git_branch = DEVELOP_YAML_SETTINGS["git_repository"][0]["branch"]
936938
_secrets_group = None
937939
if _repo.get("secrets_group_name"):
938940
_secrets_group = SecretsGroup.objects.get(name=_repo["secrets_group_name"])
@@ -1051,14 +1053,18 @@ def _setup_scheduled_job(self):
10511053
for scheduled_job in GLOBAL_YAML_SETTINGS["scheduled_job"]:
10521054
# Parse the start_time to preserve timezone info
10531055
start_time = get_scheduled_start_time(scheduled_job["start_time"])
1056+
if DEVELOP_YAML_SETTINGS.get("scheduled_job"):
1057+
job_vars = DEVELOP_YAML_SETTINGS["scheduled_job"][0]["job_vars"]
1058+
else:
1059+
job_vars = {}
10541060
scheduled_job = ScheduledJob(
10551061
name=scheduled_job["name"],
10561062
task=job.class_path,
10571063
interval=scheduled_job["interval"],
10581064
start_time=start_time,
10591065
job_model=job,
10601066
user=admin,
1061-
kwargs={},
1067+
kwargs=job_vars,
10621068
)
10631069
scheduled_job.validated_save()
10641070

0 commit comments

Comments
 (0)