Skip to content

Commit d81e5f8

Browse files
committed
Support headers environment variable for inventory plugin
1 parent 874e04a commit d81e5f8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

plugins/inventory/nb_inventory.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@
266266
default: False
267267
headers:
268268
description: Dictionary of headers to be passed to the NetBox API.
269-
type: dict
270269
default: {}
270+
env:
271+
- name: NETBOX_HEADERS
271272
"""
272273

273274
EXAMPLES = """
@@ -2121,6 +2122,12 @@ def _set_authorization(self):
21212122
)
21222123
else:
21232124
self.headers.update({"Authorization": "Token %s" % token})
2125+
headers = self.get_option("headers")
2126+
if headers:
2127+
if isinstance(headers, dict):
2128+
self.headers.update(headers)
2129+
else:
2130+
self.headers.update(json.loads(headers))
21242131

21252132
def parse(self, inventory, loader, path, cache=True):
21262133
super(InventoryModule, self).parse(inventory, loader, path)
@@ -2148,7 +2155,6 @@ def parse(self, inventory, loader, path, cache=True):
21482155
"User-Agent": "ansible %s Python %s"
21492156
% (ansible_version, python_version.split(" ", maxsplit=1)[0]),
21502157
"Content-type": "application/json",
2151-
**self.get_option("headers"),
21522158
}
21532159
self.cert = self.get_option("cert")
21542160
self.key = self.get_option("key")

0 commit comments

Comments
 (0)