ServiceNowITOM / ansible-sn-inventory

Ansible Dynamic Inventory for ServiceNow
Apache License 2.0
79 stars 45 forks source link

Added SN_TABLE option #21

Closed epicanthal closed 5 years ago

epicanthal commented 5 years ago

Provide the option to supply the CI table similar to other options, e.g. SN_FIELDS, etc.

Explanation of change starting @ line 226:

if not selection:
    selection = ['host_name', 'fqdn', 'ip_address']
for k in selection:
    if k in record:
        if record[k] != '':
            target = record[k]

The line if k in record: handles the case where a selection_order item/field is provided that does not exist in the table. e.g. the cmdb_ci_netgear table does not have a host_name field, which caused a KeyError:

Traceback (most recent call last):
  File "now.py", line 339, in <module>
    main(sys.argv)
  File "now.py", line 334, in main
    inventory.generate()
  File "now.py", line 229, in generate
    if record[k] != '':
KeyError: 'host_name'

Adding the if k in record: avoids the KeyError