From 5710faab6494045d9c722f342696253df4b69f72 Mon Sep 17 00:00:00 2001 From: LucasBoisserie Date: Mon, 31 Jan 2022 19:33:35 +0100 Subject: [PATCH] Add profile parameter for scaleway inventory (#4049) * add profile parameter for scaleway inventory * Update doc from review and add changelog * Update changelogs from review Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- .../4049-profile-for-scaleway-inventory.yml | 2 ++ plugins/inventory/scaleway.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/4049-profile-for-scaleway-inventory.yml diff --git a/changelogs/fragments/4049-profile-for-scaleway-inventory.yml b/changelogs/fragments/4049-profile-for-scaleway-inventory.yml new file mode 100644 index 0000000000..c5160eb4d4 --- /dev/null +++ b/changelogs/fragments/4049-profile-for-scaleway-inventory.yml @@ -0,0 +1,2 @@ +minor_changes: + - scaleway inventory plugin - add profile parameter ``scw_profile`` (https://github.com/ansible-collections/community.general/pull/4049). \ No newline at end of file diff --git a/plugins/inventory/scaleway.py b/plugins/inventory/scaleway.py index e36aa07bee..58b4d96fa5 100644 --- a/plugins/inventory/scaleway.py +++ b/plugins/inventory/scaleway.py @@ -31,6 +31,12 @@ DOCUMENTATION = r''' tags: description: Filter results on a specific tag. type: list + scw_profile: + description: + - The config profile to use in config file. + - By default uses the one specified as C(active_profile) in the config file, or falls back to C(default) if that is not defined. + type: string + version_added: 4.4.0 oauth_token: description: - Scaleway OAuth token. @@ -303,7 +309,13 @@ class InventoryModule(BaseInventoryPlugin, Constructable): if not oauth_token and os.path.exists(scw_config_path): with open(scw_config_path) as fh: scw_config = yaml.safe_load(fh) - active_profile = scw_config.get('active_profile', 'default') + ansible_profile = self.get_option('scw_profile') + + if ansible_profile: + active_profile = ansible_profile + else: + active_profile = scw_config.get('active_profile', 'default') + if active_profile == 'default': oauth_token = scw_config.get('secret_key') else: