From e6ae688e4727ebfb78cbb198d9a8c32f1a59a929 Mon Sep 17 00:00:00 2001 From: Karsten Jakobsen Date: Mon, 11 Feb 2019 06:40:24 +0100 Subject: [PATCH] netbox: inventory: Fix VMs do not have device_roles, but instead use roles (#50761) This makes sure that roles show up as device_role when using VMs --- lib/ansible/plugins/inventory/netbox.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/inventory/netbox.py b/lib/ansible/plugins/inventory/netbox.py index b6aae06dba9..fb2feee7021 100644 --- a/lib/ansible/plugins/inventory/netbox.py +++ b/lib/ansible/plugins/inventory/netbox.py @@ -252,7 +252,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable): def extract_device_role(self, host): try: - return [self.device_roles_lookup[host["device_role"]["id"]]] + if 'device_role' in host: + return [self.device_roles_lookup[host["device_role"]["id"]]] + elif 'role' in host: + return [self.device_roles_lookup[host["role"]["id"]]] except Exception: return