mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-09 04:00:31 -07:00
Add support for keyed_groups, groups, and compose options to linode i… (#1453)
* Add support for keyed_groups, groups, and compose options to linode inventory plugin * Changed instance,label to instance.label various lint fixes around spacing * Change self._strict to a local variable as it's no longer needed in other methods * Modified DESCRIPTION to add a version_added property to each of the new options. * Add Changelog fragment * Minor changes to the changelog fragment * Replace 'the standard' with 'support for' * Update description to note that the inventory groups are created by default from the group attribute not tags and that the group attribute has been depricated by Linode. * Remove trailing space in description * Add period to changelog fragment Co-authored-by: Clinton Bunch <cdbunch@zeus.int.zentaur.org>
This commit is contained in:
parent
09e2699d1c
commit
58a9287689
2 changed files with 50 additions and 3 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
minor_changes:
|
||||||
|
- linode inventory plugin - add support for ``keyed_groups``, ``groups``,
|
||||||
|
and ``compose`` options
|
||||||
|
(https://github.com/ansible-collections/community.general/issues/1326).
|
|
@ -17,7 +17,10 @@ DOCUMENTATION = r'''
|
||||||
- Reads inventories from the Linode API v4.
|
- Reads inventories from the Linode API v4.
|
||||||
- Uses a YAML configuration file that ends with linode.(yml|yaml).
|
- Uses a YAML configuration file that ends with linode.(yml|yaml).
|
||||||
- Linode labels are used by default as the hostnames.
|
- Linode labels are used by default as the hostnames.
|
||||||
- The inventory groups are built from groups and not tags.
|
- The default inventory groups are built from groups (deprecated by
|
||||||
|
Linode) and not tags.
|
||||||
|
extends_documentation_fragment:
|
||||||
|
- constructed
|
||||||
options:
|
options:
|
||||||
plugin:
|
plugin:
|
||||||
description: marks this as an instance of the 'linode' plugin
|
description: marks this as an instance of the 'linode' plugin
|
||||||
|
@ -38,6 +41,14 @@ DOCUMENTATION = r'''
|
||||||
default: []
|
default: []
|
||||||
type: list
|
type: list
|
||||||
required: false
|
required: false
|
||||||
|
strict:
|
||||||
|
version_added: 2.0.0
|
||||||
|
compose:
|
||||||
|
version_added: 2.0.0
|
||||||
|
groups:
|
||||||
|
version_added: 2.0.0
|
||||||
|
keyed_groups:
|
||||||
|
version_added: 2.0.0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
|
@ -51,13 +62,27 @@ regions:
|
||||||
- eu-west
|
- eu-west
|
||||||
types:
|
types:
|
||||||
- g5-standard-2
|
- g5-standard-2
|
||||||
|
|
||||||
|
# Example with keyed_groups, groups, and compose
|
||||||
|
plugin: community.general.linode
|
||||||
|
access_token: foobar
|
||||||
|
keyed_groups:
|
||||||
|
- key: tags
|
||||||
|
separator: ''
|
||||||
|
- key: region
|
||||||
|
prefix: region
|
||||||
|
groups:
|
||||||
|
webservers: "'web' in (tags|list)"
|
||||||
|
mailservers: "'mail' in (tags|list)"
|
||||||
|
compose:
|
||||||
|
ansible_port: 2222
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ansible.errors import AnsibleError, AnsibleParserError
|
from ansible.errors import AnsibleError, AnsibleParserError
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin
|
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -68,7 +93,7 @@ except ImportError:
|
||||||
HAS_LINODE = False
|
HAS_LINODE = False
|
||||||
|
|
||||||
|
|
||||||
class InventoryModule(BaseInventoryPlugin):
|
class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
|
|
||||||
NAME = 'community.general.linode'
|
NAME = 'community.general.linode'
|
||||||
|
|
||||||
|
@ -203,9 +228,27 @@ class InventoryModule(BaseInventoryPlugin):
|
||||||
|
|
||||||
self._get_instances_inventory()
|
self._get_instances_inventory()
|
||||||
|
|
||||||
|
strict = self.get_option('strict')
|
||||||
regions, types = self._get_query_options(config_data)
|
regions, types = self._get_query_options(config_data)
|
||||||
self._filter_by_config(regions, types)
|
self._filter_by_config(regions, types)
|
||||||
|
|
||||||
self._add_groups()
|
self._add_groups()
|
||||||
self._add_instances_to_groups()
|
self._add_instances_to_groups()
|
||||||
self._add_hostvars_for_instances()
|
self._add_hostvars_for_instances()
|
||||||
|
for instance in self.instances:
|
||||||
|
variables = self.inventory.get_host(instance.label).get_vars()
|
||||||
|
self._add_host_to_composed_groups(
|
||||||
|
self.get_option('groups'),
|
||||||
|
variables,
|
||||||
|
instance.label,
|
||||||
|
strict=strict)
|
||||||
|
self._add_host_to_keyed_groups(
|
||||||
|
self.get_option('keyed_groups'),
|
||||||
|
variables,
|
||||||
|
instance.label,
|
||||||
|
strict=strict)
|
||||||
|
self._set_composite_vars(
|
||||||
|
self.get_option('compose'),
|
||||||
|
variables,
|
||||||
|
instance.label,
|
||||||
|
strict=strict)
|
||||||
|
|
Loading…
Add table
Reference in a new issue