noderings.cloud.noderings inventory – NodeRings virtual machines as an Ansible inventory

Note

This inventory plugin is part of the noderings.cloud collection (version 0.2.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install noderings.cloud.

To use it in a playbook, specify: noderings.cloud.noderings.

New in noderings.cloud 0.1.0

Synopsis

  • Reads the organization’s virtual machines from the NodeRings API and adds them as hosts.

  • Hosts are grouped by tag (noderings_tag_<tag>), city, country, hosting provider, plan code, billing type and power state. More groups and variables can be built with keyed_groups, groups and compose.

  • The inventory file name must end with noderings.yml or noderings.yaml.

Parameters

Parameter

Comments

api_timeout

integer

Timeout in seconds for a single HTTP request.

Default: 60

api_token

aliases: token

string

A NodeRings service-account token.

Can be a Jinja template, for example {{ lookup('ansible.builtin.env', 'MY_TOKEN' }}).

Configuration:

api_url

string

Base URL of the NodeRings API.

Default: "https://api.noderings.com"

Configuration:

cache

boolean

Toggle to enable/disable the caching of the inventory’s source data, requires a cache plugin setup to work.

Choices:

  • false ← (default)

  • true

Configuration:

cache_connection

string

Cache connection data or path, read cache plugin documentation for specifics.

Configuration:

cache_plugin

string

Cache plugin to use for the inventory’s source data.

Default: "memory"

Configuration:

cache_prefix

string

Prefix to use for cache plugin files/tables.

Default: "ansible_inventory_"

Configuration:

cache_timeout

integer

Cache duration in seconds.

Default: 3600

Configuration:

compose

dictionary

Create vars from jinja2 expressions.

Default: {}

connect_via

string

Which address to set as ansible_host.

Choices:

  • "ipv4" ← (default)

  • "ipv6"

default_groups

boolean

Add the built-in groups (tag, city, country, provider, plan code, billing type, power state).

Choices:

  • false

  • true ← (default)

groups

dictionary

Add hosts to group based on Jinja2 conditionals.

Default: {}

hostname

string

What to name each host.

hostname uses the VM’s hostname, id its ID, ipv4 and ipv6 its address.

Choices:

  • "hostname" ← (default)

  • "id"

  • "ipv4"

  • "ipv6"

keyed_groups

list / elements=dictionary

Add hosts to group based on the values of a variable.

Default: []

default_value

string

added in ansible-core 2.12

The default value when the host variable’s value is None or an empty string.

This option is mutually exclusive with keyed_groups[].trailing_separator.

key

string

The key from input dictionary used to generate groups.

parent_group

string

parent group for keyed group.

prefix

string

A keyed group name will start with this prefix.

Default: ""

separator

string

separator used to build the keyed group name.

Default: "_"

trailing_separator

boolean

added in ansible-core 2.12

Set this option to false to omit the keyed_groups[].separator after the host variable when the value is None or an empty string.

This option is mutually exclusive with keyed_groups[].default_value.

Choices:

  • false

  • true ← (default)

leading_separator

boolean

added in ansible-core 2.11

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.

Choices:

  • false

  • true ← (default)

organization_id

string

Organization to read, sent as X-Organization-ID. Defaults to the token’s organization.

Configuration:

plugin

string / required

Must be noderings.cloud.noderings.

Choices:

  • "noderings.cloud.noderings"

states

list / elements=string

Only include VMs in these power states. Leave empty for all.

Choices:

  • "running"

  • "stopped"

  • "created"

  • "reinstalling"

  • "unknown"

Default: []

strict

boolean

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.

Choices:

  • false ← (default)

  • true

tags

list / elements=string

Only include VMs that have all of these tags.

Default: []

use_extra_vars

boolean

added in ansible-core 2.11

Merge extra vars into the available variables for composition (highest precedence).

Choices:

  • false ← (default)

  • true

Configuration:

validate_certs

boolean

Whether to validate the API’s TLS certificate.

Choices:

  • false

  • true ← (default)

variable_prefix

string

Prefix of the host variables holding the VM’s fields, for example noderings_ipv4.

Default: "noderings_"

Note

Configuration entries listed above for each entry type (Ansible variable, environment variable, and so on) have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up. The entry types are also ordered by precedence from low to high priority order. For example, an ansible.cfg entry (further up in the list) is overwritten by an Ansible variable (further down in the list).

Notes

Note

  • Inventories are not finalized at this stage, so the auto populated all and ungrouped groups will only reflect what previous inventory sources explicitly added to them.

  • Runtime ‘magic variables’ are not available during inventory construction. For example, groups and hostvars do not exist yet.

Examples

# noderings.yml: every VM, grouped automatically
plugin: noderings.cloud.noderings

# noderings.yml: only running production servers, plus a group per distro
plugin: noderings.cloud.noderings
tags: [prod]
states: [running]
keyed_groups:
  - key: noderings_distro
    prefix: distro
compose:
  ansible_user: "'root'"

# noderings.yml: cache the API answer for five minutes
plugin: noderings.cloud.noderings
cache: true
cache_plugin: ansible.builtin.jsonfile
cache_connection: /tmp/noderings-inventory
cache_timeout: 300

Authors

  • Shaygun (@shaygun)