unbyte.gridscale.gs_inventory inventory – Ansible dynamic inventory plugin for gridscale.
Note
This inventory plugin is part of the unbyte.gridscale collection (version 0.1.4).
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 git+https://github.com/unbyte-de/gridscale-ansible-collection.git,0.1.4
.
You need further requirements to be able to use this inventory plugin,
see Requirements for details.
To use it in a playbook, specify: unbyte.gridscale.gs_inventory
.
Synopsis
Reads the inventory from gridscale API.
Uses a YAML configuration file that ends with
gs_inventory.yml
orgs_inventory.yaml
.
Requirements
The below requirements are needed on the local controller node that executes this inventory.
gs_api_client >= 2.2.1
Parameters
Parameter |
Comments |
---|---|
The token for gridscale API. This token is project specific. So we can only get servers per project. Configuration:
|
|
Toggle to enable/disable the caching of the inventory’s source data, requires a cache plugin setup to work. Choices:
Configuration:
|
|
Cache connection data or path, read cache plugin documentation for specifics. Configuration:
|
|
Cache plugin to use for the inventory’s source data. Default: Configuration:
|
|
Prefix to use for cache plugin files/tables Default: Configuration:
|
|
Cache duration in seconds Default: Configuration:
|
|
Create vars from jinja2 expressions. Default: |
|
Add hosts to group based on Jinja2 conditionals. Default: |
|
Populate inventory with instances in this group.
This doesn’t filter default groups “all” and “ungrouped”, and also groups defined via Default: |
|
Add only these vars to hosts in inventory.
This doesn’t filter vars generated via Default: |
|
A template for the server hostname. Variables are the host variables. If not defined, the server name from gridscale is used. |
|
The prefix for host variable names that are coming from gridscale. Default: |
|
The suffix for host variable names that are coming from gridscale. Default: |
|
Add hosts to group based on the values of a variable. Default: |
|
The default value when the host variable’s value is an empty string. This option is mutually exclusive with |
|
The key from input dictionary used to generate groups |
|
parent group for keyed group |
|
A keyed group name will start with this prefix Default: |
|
separator used to build the keyed group name Default: |
|
Set this option to This option is mutually exclusive with Choices:
|
|
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:
|
|
Populate inventory with instances in this location. Default: |
|
The group all servers are automatically added to. |
|
gridscale inventory plugin name. Choices:
|
|
Populate inventory with instances with this status. Default: |
|
If Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default. Choices:
|
|
Merge extra vars into the available variables for composition (highest precedence). Choices:
Configuration:
|
|
Examples
# 'GRIDSCALE_API_TOKEN' and 'GRIDSCALE_USER_UUID' set as env vars
plugin: unbyte.gridscale.gs_inventory
---
plugin: unbyte.gridscale.gs_inventory
api_token: "{{ _vault_gridscale_api_token }}"
user_uuid: "{{ _vault_gridscale_user_uuid }}"
main_group: gridscale
# Filter with location and status
locations_filter:
- "de/fra"
status_filter:
- "active"
---
plugin: unbyte.gridscale.gs_inventory
# Generate groups based on hostname
groups:
# k8s: "'k8s' in hostname"
cp: "'master' in hostname"
node: "'master' not in hostname and 'node' in hostname"
# Generate groups based on "location" host var
keyed_groups:
- key: location
separator: "" # Default is "_".
# Create new vars based on "location" host var
compose:
location_country: location.split("/")[0]
location_iata: location.split("/")[-1]
# Use only these vars in inventory
host_vars_filter:
- ansible_host
- location
---
plugin: unbyte.gridscale.gs_inventory
# Generate groups based on hostname
groups:
cp: "'master' in hostname"
node: "'master' not in hostname and 'node' in hostname"
# Filter out everything except ones in "cp" group
groups_filter:
- "cp"
---
plugin: unbyte.gridscale.gs_inventory
main_group: gridscale
hostname_template: "example-{{ location.replace('/', '-') }}-{{ hostname }}"
hostvars_prefix: "prefix_"
hostvars_suffix: "_suffix"
groups:
cp: "'master' in prefix_hostname_suffix"
node: "'master' not in prefix_hostname_suffix and 'node' in prefix_hostname_suffix"
keyed_groups:
- key: prefix_location_suffix
separator: ""
host_vars_filter:
- ansible_host
- prefix_location_suffix
- prefix_hostname_suffix