stephrobert.scaleway.compute inventory – Scaleway compute dynamic inventory

Note

This inventory plugin is part of the stephrobert.scaleway collection (version 0.7.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 stephrobert.scaleway. You need further requirements to be able to use this inventory plugin, see Requirements for details.

To use it in a playbook, specify: stephrobert.scaleway.compute.

New in stephrobert.scaleway 0.1.0

Synopsis

  • Builds an Ansible inventory from a Scaleway account.

  • Discovers hosts product by product, then enriches them with their private networks and VPCs by listing IPAM once per region rather than once per network interface.

  • Uses a configuration file whose name ends with scaleway.yml or scw.yml.

Requirements

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

  • scaleway >= 2.9.0

Parameters

Parameter

Comments

access_key

string

Scaleway API access key.

Configuration:

address

dictionary

Restrict ansible_host to one private network.

Accepts private_network, a name or an ID, or private_network_id.

Default: {}

address_priority

list / elements=string

Address families to try, in order, when setting ansible_host.

Default: ["private_ipv4", "public_ipv4", "private_ipv6", "public_ipv6"]

api_allow_insecure

boolean

Reach the endpoint without verifying its TLS certificate.

Choices:

  • false

  • true

api_url

string

URL of the Scaleway API endpoint.

Point it at a local emulator to build an inventory without credentials.

Falls back to the Scaleway configuration file, then to https://api.scaleway.com. It carries no default on purpose: a default is never unset, so it would always override the profile.

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: {}

config_file

path

Path to the Scaleway configuration file.

Configuration:

exclude

dictionary

Drop hosts matching these tags or states, after every other filter.

Default: {}

group_by

list / elements=string

Axes used to build the native scw_* groups.

Choices:

  • "product" ← (default)

  • "project" ← (default)

  • "region" ← (default)

  • "zone" ← (default)

  • "state"

  • "tags"

  • "vpc"

  • "private_network"

Default: ["product", "project", "region", "zone"]

groups

dictionary

Add hosts to group based on Jinja2 conditionals.

Default: {}

hostnames

list / elements=string

Sources for inventory_hostname, in order of precedence.

Accepts name, id, public_ipv4, public_ipv6, private_ipv4, private_ipv6 and tag:KEY, which reads a KEY=value tag.

The names hostname, vpc_ipv4 and vpc_ipv6 used by the official collection are accepted as aliases.

Collisions are resolved by appending the zone, then the resource ID.

Default: ["name", "id"]

include_raw

boolean

Expose the raw API object as scaleway_raw. Off by default.

Choices:

  • false ← (default)

  • true

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

Default Organization ID.

Configuration:

organizations

list / elements=string

Organization IDs to restrict discovery to.

Default: []

plugin

string / required

The name of this plugin.

Choices:

  • "stephrobert.scaleway.compute"

products

list / elements=string

Products to discover hosts from.

all means every host product this plugin version supports.

Default: ["all"]

profile

string

Name of the profile to read in the Scaleway configuration file.

Configuration:

project_id

string

Default Project ID.

Configuration:

projects

list / elements=string

Project IDs to restrict discovery to. Empty means the profile default.

Default: []

regions

list / elements=string

Regions used to build the network index. Derived from the zones when empty.

Default: []

require_address

boolean

Drop hosts for which no address could be selected.

False keeps them without ansible_host, which is still useful for tasks delegated to localhost that act through the Scaleway API.

Choices:

  • false ← (default)

  • true

secret_key

string

Scaleway API secret key.

Configuration:

states

list / elements=string

Only keep hosts in these states.

Default: []

strict

boolean

Fail the inventory when a provider fails, instead of returning an incomplete fleet. Refused credentials are fatal immediately; a product absent from a zone stays a warning, because that is not an outage.

Ansible downgrades an inventory failure to a warning and exits zero, so on its own this option writes the reason and stops nothing. To make it stop a run, set ANSIBLE_INVENTORY_ANY_UNPARSED_IS_FAILED=True in the environment, or any_unparsed_is_failed = True under [inventory] in ansible.cfg. Without it, a revoked key produces a green run on an empty fleet.

Choices:

  • false

  • true ← (default)

tags

list / elements=string

Only keep hosts carrying these tags.

Default: []

tags_match

string

Whether a host must carry any or all of the requested tags.

Choices:

  • "any" ← (default)

  • "all"

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:

user_agent

string

Value of the User-Agent header sent to the API.

zones

list / elements=string

Zones to query. Empty means every zone the product declares.

Default: []

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

  • The credential options are declared here rather than inherited from the module documentation fragment. A module option carries no env key, so its default would silently win over the environment, and a run meant for a local emulator would reach the real Scaleway API instead.

  • 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

# Four inventory files, each complete and each meant to be copied whole. Save
# one as `scaleway.yml` and run `ansible-inventory -i scaleway.yml --graph`.

# 1. The smallest thing that works: the usual Scaleway profile decides the rest.
plugin: stephrobert.scaleway.compute

---
# 2. Production: one project, one region, the machines that are running.
plugin: stephrobert.scaleway.compute
projects:
  - 11111111-1111-1111-1111-111111111111
products:
  - instance
regions:
  - fr-par
states:
  - running
tags:
  - production
address_priority:
  - private_ipv4
  - public_ipv4
group_by:
  - product
  - project
  - zone
  - tags
cache: true

---
# 3. Reach the machines over one named private network. Useful when a machine
# sits on several: without this, the first one found wins, which is not a
# decision. `require_address` then turns a machine with no address on that
# network into an error rather than a silent absence from the inventory.
plugin: stephrobert.scaleway.compute
address:
  private_network: production
require_address: true

---
# 4. Groups and variables built by Ansible itself, from what the plugin
# exposes. `scaleway_instance` carries the API object, so any of its fields can
# key a group.
plugin: stephrobert.scaleway.compute
compose:
  ansible_user: "'ubuntu'"
keyed_groups:
  - prefix: scw_type
    key: scaleway_instance.commercial_type

Authors

  • Stéphane Robert (@stephrobert)