Unable to provision a config-template with local data source via the REST API #8485

Closed
opened 2025-12-29 20:37:19 +01:00 by adam · 7 comments
Owner

Originally created by @desnoe on GitHub (Aug 18, 2023).

Originally assigned to: @desnoe on GitHub.

NetBox version

v3.6.1

Python version

3.11.4

Steps to Reproduce

  1. Start from a fresh NetBox instance, configure an API token and configure these 2 environment variables:
TOKEN=mynetboxtoken
NETBOX_URL=http://my.netbox.url

Please replace with values relevant to your NetBox instance.

  1. Create /etc/netbox/templates directory on the NetBox instance and create a trivial Jinja2 template to the NetBox instance in it:
mkdir -p /etc/netbox/templates
echo 'This is a simple Jinja2 template.' > /etc/netbox/templates/basic.j2
  1. Provision a new local data source using the REST API:
curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
$NETBOX_URL/api/core/data-sources/ \
--data '{
    "name": "templates",
    "type": "local",
    "source_url": "file:///etc/netbox/templates",
    "enabled": true
}'

Make sure it is correctly created and note down its id:

DATASOURCE_ID=1

Please replace with the id of the created object.

  1. Sync this new local data source using the REST API:
curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
$NETBOX_URL/api/core/data-sources/$DATASOURCE_ID/sync/ \
  1. Provision a new config template based on the basic.j2 Jinja2 template in this local data source using the REST API:
curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
$NETBOX_URL/api/extras/config-templates/ \
--data '{
    "name": "basic",
    "template_code": "Will be overwritten after data_file is synced",
    "data_source": {"name": "templates"},
    "data_file": {"path": "basic.j2"}
}'

Make sure it is correctly created and note down its id:

CONFIGTEMPLATE_ID=1

Please replace with the id of the created object.

  1. Sync this new config template:
curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
$NETBOX_URL/api/extras/config-templates/$CONFIGTEMPLATE_ID/sync/

Now, the config template can be used on a device or device-role.

Expected Behavior

At step 6, I expect data_file to be correctly populated in the JSON data of the POST response. I should get:

{
    ...
    "data_file": {
        ...
        "path": "basic.j2"
    },
    ...
}

Observed Behavior

At step 6, the JSON data I'm really receiving in the POST response is:

{
    ...
    "data_file": null,
    ...
}
Originally created by @desnoe on GitHub (Aug 18, 2023). Originally assigned to: @desnoe on GitHub. ### NetBox version v3.6.1 ### Python version 3.11.4 ### Steps to Reproduce 1. Start from a fresh NetBox instance, configure an API token and configure these 2 environment variables: ``` TOKEN=mynetboxtoken NETBOX_URL=http://my.netbox.url ``` Please replace with values relevant to your NetBox instance. 2. Create `/etc/netbox/templates` directory on the NetBox instance and create a trivial Jinja2 template to the NetBox instance in it: ``` mkdir -p /etc/netbox/templates echo 'This is a simple Jinja2 template.' > /etc/netbox/templates/basic.j2 ``` 4. Provision a new local data source using the REST API: ``` curl -X POST \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ $NETBOX_URL/api/core/data-sources/ \ --data '{ "name": "templates", "type": "local", "source_url": "file:///etc/netbox/templates", "enabled": true }' ``` Make sure it is correctly created and note down its id: ``` DATASOURCE_ID=1 ``` Please replace with the id of the created object. 5. Sync this new local data source using the REST API: ``` curl -X POST \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ $NETBOX_URL/api/core/data-sources/$DATASOURCE_ID/sync/ \ ``` 6. Provision a new config template based on the `basic.j2` Jinja2 template in this local data source using the REST API: ``` curl -X POST \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ $NETBOX_URL/api/extras/config-templates/ \ --data '{ "name": "basic", "template_code": "Will be overwritten after data_file is synced", "data_source": {"name": "templates"}, "data_file": {"path": "basic.j2"} }' ``` Make sure it is correctly created and note down its id: ``` CONFIGTEMPLATE_ID=1 ``` Please replace with the id of the created object. 7. Sync this new config template: ``` curl -X POST \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ $NETBOX_URL/api/extras/config-templates/$CONFIGTEMPLATE_ID/sync/ ``` Now, the config template can be used on a device or device-role. ### Expected Behavior At step 6, I expect `data_file` to be correctly populated in the JSON data of the POST response. I should get: ``` { ... "data_file": { ... "path": "basic.j2" }, ... } ``` ### Observed Behavior At step 6, the JSON data I'm really receiving in the POST response is: ``` { ... "data_file": null, ... } ```
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:37:19 +01:00
adam closed this issue 2025-12-29 20:37:19 +01:00
Author
Owner

@desnoe commented on GitHub (Aug 18, 2023):

Check this link for the discussion on Slack:
https://netdev-community.slack.com/archives/C01P0FRSXRV/p1692216027078659

@desnoe commented on GitHub (Aug 18, 2023): Check this link for the discussion on Slack: https://netdev-community.slack.com/archives/C01P0FRSXRV/p1692216027078659
Author
Owner

@jeremystretch commented on GitHub (Aug 21, 2023):

Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.

@jeremystretch commented on GitHub (Aug 21, 2023): Thank you for opening a bug report. Unfortunately, the information you have provided is not sufficient for someone else to attempt to reproduce the reported behavior. Remember, each bug report must include detailed steps that someone else can follow on a clean, empty NetBox installation to reproduce the exact problem you're experiencing. These instructions should include the creation of any involved objects, any configuration changes, and complete accounting of the actions being taken. Also be sure that your report does not reference data on the public NetBox demo, as that is subject to change at any time by an outside party and cannot be relied upon for bug reports.
Author
Owner

@jeremystretch commented on GitHub (Aug 28, 2023):

This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.

@jeremystretch commented on GitHub (Aug 28, 2023): This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.
Author
Owner

@desnoe commented on GitHub (Sep 14, 2023):

I have added more details to reproduce the problem, step by step, and I hope this will be clear enough. Could you please reopen this issue ?

I also have a bugfix ready.

@desnoe commented on GitHub (Sep 14, 2023): I have added more details to reproduce the problem, step by step, and I hope this will be clear enough. Could you please reopen this issue ? I also have a bugfix ready.
Author
Owner

@jeremystretch commented on GitHub (Sep 21, 2023):

This occurs because the data_source and data_file fields on ConfigTemplateSerializer are read-only. I can't say at this point what the reasoning was for preventing write operations to these fields.

@desnoe I'll assign this to you as you mention having a fix prepared. Thanks!

@jeremystretch commented on GitHub (Sep 21, 2023): This occurs because the `data_source` and `data_file` fields on ConfigTemplateSerializer are read-only. I can't say at this point what the reasoning was for preventing write operations to these fields. @desnoe I'll assign this to you as you mention having a fix prepared. Thanks!
Author
Owner

@desnoe commented on GitHub (Sep 22, 2023):

Thanks @jeremystretch, I just opened the PR.
I only modified data_filewhich was read-only, data_source is not read-only in ConfigTemplateSerializer and is already working fine through the API.

@desnoe commented on GitHub (Sep 22, 2023): Thanks @jeremystretch, I just opened the PR. I only modified `data_file`which was read-only, `data_source` is not read-only in ConfigTemplateSerializer and is already working fine through the API.
Author
Owner

@jeremystretch commented on GitHub (Sep 25, 2023):

I only modified data_file which was read-only, data_source is not read-only in ConfigTemplateSerializer and is already working fine through the API.

My mistake, I must have misread the code.

@jeremystretch commented on GitHub (Sep 25, 2023): > I only modified `data_file` which was read-only, `data_source` is not read-only in ConfigTemplateSerializer and is already working fine through the API. My mistake, I must have misread the code.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8485