stephrobert.scaleway.resource_id lookup – Resolve a Scaleway resource name into its identifier

Note

This lookup 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 lookup plugin, see Requirements for details.

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

New in stephrobert.scaleway 0.6.0

Synopsis

  • Half of the modules in this collection act on a sub-resource carrying its own identifier, which only the matching _info module returns. This lookup returns that identifier from the name you already know, so a playbook does not have to call a module, register its result and dig a UUID out of it.

  • The resolution table is derived from the versioned API contracts, never written by hand. A resource that stops being listable, or that loses its name field upstream, leaves the table at the next generation instead of staying a promise.

  • The name must match exactly. The Scaleway name query filter matches by prefix, which the contract states itself for Instances: server1 returns both server100 and server1. The filter is sent to avoid paginating a whole fleet, and the exact comparison is always done locally.

Requirements

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

  • scaleway >= 2.9.0

Terms

Parameter

Comments

Terms

string / required

The identifier parameter you are trying to fill, such as server_id.

Exactly one, because a lookup that resolved several at once could not say which scope belonged to which.

Keyword parameters

This describes keyword parameters of the lookup. These are the values key1=value1, key2=value2 and so on in the following examples: lookup('stephrobert.scaleway.resource_id', key1=value1, key2=value2, ...) and query('stephrobert.scaleway.resource_id', key1=value1, key2=value2, ...)

Parameter

Comments

access_key

string

Scaleway API access key.

Configuration:

api_allow_insecure

boolean

Reach the endpoint without verifying its TLS certificate.

Choices:

  • false

  • true

api_timeout

integer

Seconds to wait for a single API call.

api_url

string

URL of the Scaleway API endpoint.

Point it at a local emulator to resolve names 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:

config_file

path

Path to the Scaleway configuration file.

Configuration:

name

string / required

Exact name of the resource to resolve.

organization_id

string

Default Organization ID.

Configuration:

profile

string

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

Configuration:

project_id

string

Default Project ID.

Configuration:

region

string

Region the resource lives in, for regional resources.

secret_key

string

Scaleway API secret key.

Configuration:

user_agent

string

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

zone

string

Zone the resource lives in, for zoned resources.

Notes

Note

  • When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters: lookup('stephrobert.scaleway.resource_id', term1, term2, key1=value1, key2=value2) and query('stephrobert.scaleway.resource_id', term1, term2, key1=value1, key2=value2)

  • Exactly one match returns the identifier. No exact match and several exact matches both fail, and the message names what was found. Returning the first of several candidates would make the playbook act on a resource nobody designated.

  • 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 lookup meant for a local emulator would reach the real Scaleway API instead.

Examples

- name: Reboot the machine named web-01 without knowing its identifier
  stephrobert.scaleway.instance_server_action:
    zone: fr-par-1
    server_id: >-
      {{ lookup('stephrobert.scaleway.resource_id', 'server_id',
                zone='fr-par-1', name='web-01') }}
    action: reboot
  delegate_to: localhost

- name: Update the backend named api of a named load balancer
  stephrobert.scaleway.lb_backend:
    zone: fr-par-1
    lb_id: "{{ load_balancer_id }}"
    backend_id: >-
      {{ lookup('stephrobert.scaleway.resource_id', 'backend_id',
                zone='fr-par-1', lb_id=load_balancer_id, name='api') }}
    forward_port: 8080
  delegate_to: localhost

- name: Resolve the load balancer itself, then a backend inside it
  ansible.builtin.set_fact:
    load_balancer_id: >-
      {{ lookup('stephrobert.scaleway.resource_id', 'lb_id',
                zone='fr-par-1', name='public') }}

Return Value

Key

Description

Return value

list / elements=string

The identifier of the single resource carrying that exact name.

Returned: success

Authors

  • Stéphane Robert (@stephrobert)