servicenow.servicenow.now – ServiceNow Inventory Plugin

Note

This plugin is part of the servicenow.servicenow collection (version 1.0.6).

To install it use: ansible-galaxy collection install servicenow.servicenow.

To use it in a playbook, specify: servicenow.servicenow.now.

New in version 2.10: of servicenow.servicenow

Synopsis

  • ServiceNow Inventory plugin.

Requirements

The below requirements are needed on the local controller node that executes this inventory.

  • python requests (requests)

  • netaddr

Parameters

Parameter Choices/Defaults Configuration Comments
cache
boolean
    Choices:
  • no ←
  • yes
ini entries:

[inventory]
cache = no

env:ANSIBLE_INVENTORY_CACHE
Toggle to enable/disable the caching of the inventory's source data, requires a cache plugin setup to work.
cache_connection
string
ini entries:

[defaults]
fact_caching_connection = None

[inventory]
cache_connection = None

env:ANSIBLE_CACHE_PLUGIN_CONNECTION
env:ANSIBLE_INVENTORY_CACHE_CONNECTION
Cache connection data or path, read cache plugin documentation for specifics.
cache_plugin
string
Default:
"memory"
ini entries:

[defaults]
fact_caching = memory

[inventory]
cache_plugin = memory

env:ANSIBLE_CACHE_PLUGIN
env:ANSIBLE_INVENTORY_CACHE_PLUGIN
Cache plugin to use for the inventory's source data.
cache_prefix
string
Default:
"ansible_inventory_"
ini entries:

[default]
fact_caching_prefix = ansible_inventory_

[inventory]
cache_prefix = ansible_inventory_

env:ANSIBLE_CACHE_PLUGIN_PREFIX
env:ANSIBLE_INVENTORY_CACHE_PLUGIN_PREFIX
Prefix to use for cache plugin files/tables
cache_timeout
integer
Default:
3600
ini entries:

[defaults]
fact_caching_timeout = 3600

[inventory]
cache_timeout = 3600

env:ANSIBLE_CACHE_PLUGIN_TIMEOUT
env:ANSIBLE_INVENTORY_CACHE_TIMEOUT
Cache duration in seconds
compose
dictionary
Default:
{}
Create vars from jinja2 expressions.
enhanced
boolean
    Choices:
  • no ←
  • yes
Enable enhanced inventory which provides relationship information from CMDB.
Requires installation of Update Set located in update_sets directory.
enhanced_groups
boolean
    Choices:
  • no
  • yes ←
enable enhanced groups from CMDB relationships. Only used if enhanced is enabled.
fields
list / elements=string
Default:
"ip_address,fqdn,host_name,sys_class_name,name"
Comma seperated string providing additional table columns to add as host vars to each inventory host.
filter_results
string
Default:
""
Filter results with sysparm_query encoded query string syntax. Complete list of operators available for filters and queries.
groups
dictionary
Default:
{}
Add hosts to group based on Jinja2 conditionals.
host
string
env:SN_HOST
The ServiceNow hostname.
This value is FQDN for ServiceNow host.
If the value is not specified in the task, the value of environment variable SN_HOST will be used instead.
Mutually exclusive with instance.
instance
string
env:SN_INSTANCE
The ServiceNow instance name, without the domain, service-now.com.
If the value is not specified in the task, the value of environment variable SN_INSTANCE will be used instead.
keyed_groups
list / elements=string
Default:
[]
Add hosts to group based on the values of a variable.
leading_separator
boolean
added in 2.11 of ansible.builtin
    Choices:
  • no
  • yes ←
Use in conjunction with keyed_groups.
By default, a keyed group that does not have a prefix or a separator provided will have a name that starts with an underscore.
This is because the default prefix is "" and the default separator is "_".
Set this option to False to omit the leading underscore (or other separator) if no prefix is given.
If the group name is derived from a mapping the separator is still used to concatenate the items.
To not use a separator in the group name at all, set the separator for the keyed group to an empty string instead.
password
string / required
env:SN_PASSWORD
Password for username.
If the value is not specified, the value of environment variable SN_PASSWORD will be used instead.
plugin
string / required
    Choices:
  • servicenow.servicenow.now
The name of the ServiceNow Inventory Plugin, this should always be 'servicenow.servicenow.now'.
proxy
string
Default:
""
Proxy server to use for requests to ServiceNow.
selection_order
list / elements=string
Default:
"ip_address,fqdn,host_name,name"
Comma seperated string providing ability to define selection preference order.
strict
boolean
    Choices:
  • no ←
  • yes
If yes make invalid entries a fatal error, otherwise skip and continue.
Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default.
table
string
Default:
"cmdb_ci_server"
The ServiceNow table to query.
use_extra_vars
boolean
added in 2.11 of ansible.builtin
    Choices:
  • no ←
  • yes
ini entries:

[inventory_plugins]
use_extra_vars = no

env:ANSIBLE_INVENTORY_USE_EXTRA_VARS
Merge extra vars into the available variables for composition (highest precedence).
username
string
env:SN_USERNAME
Name of user for connection to ServiceNow.
If the value is not specified, the value of environment variable SN_USERNAME will be used instead.

Examples

# Simple Inventory Plugin example
plugin: servicenow.servicenow.now
instance: dev89007
username: admin
password: password
keyed_groups:
  - key: sn_sys_class_name | lower
    prefix: ''
    separator: ''

# Using Keyed Groups
plugin: servicenow.servicenow.now
host: servicenow.mydomain.com
username: admin
password: password
fields: [name,host_name,fqdn,ip_address,sys_class_name, install_status, classification,vendor]
keyed_groups:
  - key: sn_classification | lower
    prefix: 'env'
  - key: sn_vendor | lower
    prefix: ''
    separator: ''
  - key: sn_sys_class_name | lower
    prefix: ''
    separator: ''
  - key: sn_install_status | lower
    prefix: 'status'

# Compose hostvars
plugin: servicenow.servicenow.now
instance: dev89007
username: admin
password: password
fields:
  - name
  - sys_tags
compose:
  sn_tags: sn_sys_tags.replace(" ", "").split(',')
  ansible_host: sn_ip_address
keyed_groups:
  - key: sn_tags | lower
    prefix: 'tag'

Authors

  • Will Tome (@willtome)

  • Alex Mittell (@alex_mittell)