Commit graph

742 commits

Author SHA1 Message Date
Vi P
307839b810
Remove plugin option from inventory config for compatibility with passthrough plugins
One niche but useful feature of Ansible inventory plugins is the ability to call one plugin from another. For example, you can write a custom plugin (`my.plugin.multi_cloud`) that acts as a sort of normalization interface between project inventories deployed on multiple cloud platforms. This makes it feasible to create a single set of Ansible Playbooks that can act on hosts across cloud platforms because they can expect managed node (inventory host) data to be consistent across those cloud platform vendors.

For example, `my.plugin.multi_cloud` inventory plugin might look something like the following code, which simply dynamically loads one or another underlying (upstream) vendor'ed inventory plugins based on the value of the shell environment variable called `CLOUD_PLATFORM`:

```python
#!/usr/bin/env python3

from ansible.errors import AnsibleError, AnsibleParserError
from ansible.plugins.inventory import BaseInventoryPlugin
from ansible.plugins.loader import inventory_loader
import os

class InventoryModule(BaseInventoryPlugin):

    def parse(self, inventory, loader, path, cache=True):
        super(InventoryModule, self).parse(inventory, loader, path)

        # Map the cloud platform to the appropriate vendor's inventory plugin.
        cloud_platform = os.environ.get('CLOUD_PLATFORM', '').lower()
        if cloud_platform == 'aws':
            plugin_fqcn = 'amazon.aws.aws_ec2'
        elif cloud_platform == 'gcp':
            plugin_fqcn = 'google.cloud.gcp_compute'
        else:
            raise AnsibleParserError(
                    f"Error: Unrecognized or unset cloud platform '{cloud_platform}'. "
                    f"Set ENTROPY_CLOUD_PLATFORM to 'aws' or 'gcp'.\n"
            )

        if not inventory_loader.has_plugin(plugin_fqcn):
            raise AnsibleParserError(f"Error: '{plugin_fqcn}' inventory plugin not found.\n")

        # Load the requested plugin.
        self.inventory_plugin = inventory_loader.get(plugin_fqcn)
```

In the above example, we see code loading either this `google.cloud.gcp_compute` inventory plugin or Amazon's `amazon.aws.aws_ec2` inventory plugin.

Later, we can invoke the underlying (upstream) plugin in a passthrough manner like this:

```python
        # Passthrough to the underlying plugin.
        if self.inventory_plugin.verify_file(path):
            self.inventory_plugin.parse(inventory, loader, path)
        else:
            raise AnsibleParserError(f"Error: Inventory configuration file '{path}' failed verification by plugin '{plugin_fqcn}'")
```

However, in order for this to work, we must supply the underlying plugin with knowledge of the fact that we are calling it from a different actual plugin. This is facilitated via Ansible's built in `_redirected_names` class property. Before calling the underlying plugin's `parse()` method, we must first do:

```python
        self.inventory_plugin._redirected_names.append(InventoryModule.NAME)
```

Now the underlying plugin will be permitted to run because the underlying plugin is informing Ansible that one of the names it is permitted to use is this "redirected" (aliased) name of the calling plugin. We have effectively monkey-patched the plugin during runtime, which is exactly what we want.

Unfortunately, for _this_ `google.cloud.gcp_compute` inventory plugin, that's not enough, because of the fact that the `plugin` option in its configuration file is also checked and compared against this same name. That's something that, for example, the `amazon.aws.aws_ec2` inventory plugin _doesn't_ do, and for good reason: enforcing this check with hardcoded options breaks the built-in functionality of the Ansible module loading alias features.

That's why I'm suggesting we remove this option. It isn't needed for the `auto` inventory plugin to load the plugin correctly, nor does it ever really need to be checked once this plugin is actually running; it's already running! But its presence _does_ break existing Ansible features, and makes the above use case of a pass-through plugin, for example, infeasible.

Thanks for considering this proposal.
2025-03-14 23:12:41 -04:00
Chris Hawk
5ebc615a48 Fix doc lint errors in gcp_pubsub_subscription 2025-01-10 14:52:33 -08:00
Chris Hawk
25d53ff320 Merge branch 'master' into issue-613 2025-01-10 13:59:02 -08:00
Chris Hawk
5a395e234f
Merge pull request #652 from gomesfernandes/fix/bigquery-clustering-fields
fix: google.cloud.gcp_bigquery_table clustering fields
2024-11-11 17:05:12 -08:00
Chris Hawk
d719b0efaa
Fix a YAML doc parsing error in gcp_pubsub_subscription.py 2024-11-11 16:49:34 -08:00
Chris Hawk
68c9af276c
Update gcp_pubsub_subscription.py
Fix lint errors
2024-11-11 16:40:47 -08:00
Sieradzki, Lukasz
e89571eb91 https://github.com/ansible-collections/google.cloud/issues/657 2024-11-08 23:03:14 +01:00
Sieradzki, Lukasz
2b35fbf404 https://github.com/ansible-collections/google.cloud/issues/657 2024-11-08 23:02:23 +01:00
Sieradzki, Lukasz
8b9a2c70dd https://github.com/ansible-collections/google.cloud/issues/657 2024-11-08 18:46:49 +01:00
Sieradzki, Lukasz
6794d18478 https://github.com/ansible-collections/google.cloud/issues/653 2024-11-07 11:02:53 +01:00
Chris Hawk
537707deef Fix a compute_backend_service permadiff 2024-11-06 16:16:00 -08:00
Chris Hawk
608a8486e3 Fix many documentation lint errors 2024-11-05 14:58:14 -08:00
Chris Hawk
1a7d4e3cda Add many no_log attributes 2024-11-05 14:06:56 -08:00
Sieradzki, Lukasz
0e9c32fcde https://github.com/ansible-collections/google.cloud/issues/653 2024-11-04 21:01:26 +01:00
Chris Hawk
78b36fe3b6 Fix lint errors in the gcp_secret_manager lookup plugin 2024-11-04 10:28:23 -08:00
Chris Hawk
22804f0cdc Fix lint errors in the gcp_compute lookup plugin 2024-11-04 10:18:57 -08:00
Caty Gomes Fernandes
30858618e5 fix: gcp_bigquery_table clustering payload 2024-10-31 18:20:15 +01:00
Chris Hawk
83e84e80d5 Add a basic DOCUMENTATION string for gcp_kms_filters.py 2024-08-22 16:04:26 -07:00
Chris Hawk
bc7313854d Remove an f-string usage for backward compatibility 2024-08-22 15:40:29 -07:00
Ivan Fernandez Calvo
f7140225a8
fix: support more than 10 secrets versions on gcp_secret_manager 2024-05-23 12:31:26 +02:00
Chris Hawk
a9c0624bbd
Merge pull request #578 from dcostakos/gcp_secret_manager
Adding support for Google Secret Manager for issue 543
2024-05-22 14:41:07 -07:00
Chris Hawk
811327bc09 chore: removed unused imports 2023-11-20 11:17:25 -08:00
Chris Hawk
661f114037 chore: fix a line length lint error 2023-11-17 16:47:05 -08:00
Chris Hawk
08ada5354d fix: upgrade ansible version, address test and lint errors 2023-11-17 16:39:42 -08:00
John Jarvis
3714be2936
fix: check for labels in json dict 2023-08-30 18:44:42 +02:00
Alina Buzachis
84503b7930
Fix doc_fragments/gcp.py (#587)
Signed-off-by: Alina Buzachis <abuzachis@redhat.com>
2023-07-22 00:31:54 +00:00
Dave Costakos
40d2c9a7d5
updated plugsins based on feedback, fixed linting and documentation errors. 2023-07-14 10:33:15 -07:00
Dave Costakos
3ce29db3ee
updated plugsins based on feedback, fixed linting and documentation errors. 2023-07-14 10:31:52 -07:00
Dave Costakos
375b317692
Merge branch 'ansible-collections:master' into gcp_secret_manager 2023-07-14 10:29:52 -07:00
Irfan
75f3198605
Fix typo in documentation (#577) 2023-07-07 15:31:15 -07:00
Yusuke Tsutsumi
d1277f829b
fix: iam service account key path must not exist (#576)
Update docs to explain that the json secret key must not
already exist, or the module will try to read it.

fixes #370
2023-07-07 15:05:09 -07:00
Dave Costakos
953b06ff05
updated lookuup plugin based on comment 76eb024c25# 2023-06-22 14:36:55 -07:00
Dave Costakos
76eb024c25
Adding support for Google Secret Manager for issue 543 2023-06-21 16:24:14 -07:00
Yusuke Tsutsumi
30a4e66363
fix: use default service account if unset (#572)
`service_account_email` defaults to None if one
is not set. For gcp_compute_instance_info, this results
in an invalid request as the service account is populated
directly in the path.

Populating `default` when a value is not set fixes the error.

fixes #568
2023-06-10 11:39:44 -07:00
Shlomo Shuck
203961b045
feat: add auth support for GCP access tokens (#574)
Introduce choice "accesstoken" for auth_kind for modules
Introduce optional access_token string param that falls back to
  GCP_ACCESS_TOKEN env var
2023-06-10 11:20:57 -07:00
Samir Faci
86e0cef208 Adding support for ip_allocation_policy->stack_type 2023-04-22 12:28:05 -07:00
Samir Faci
cd35f3bce6 Adding DataPlane V2 support.
fix for #566
2023-04-22 12:28:05 -07:00
Yusuke Tsutsumi
12438f9bfb fix: correct gcp_compute_instance_info filter docs
The link for filter documentation was pointing to
gcloud, which isn't correct as gcp_compute_instance_info
communicates with the API.

fixes #549
2023-02-18 12:20:50 -08:00
Yusuke Tsutsumi
252f215f2c fix: remove version_added in gcp_compute
The version_added field is documented for a very small set of
fields, specifically in gcp_compute today.

Removing these values as they are specifying the ansible-core version
which is confusing for those who are installing via ansible-galaxy,
and the value is not set for any other module.

fixes #550.
2023-02-18 11:46:35 -08:00
laithalissa
5d56d3f2d2 Update example inventory filter
Update the example inventory filter to not use a machineType filter. The existing
machineType filter example is erroneous, see
https://github.com/ansible-collections/google.cloud/issues/421#issuecomment-1361680826
Change the filter to use "status = RUNNING"
2023-02-10 16:39:28 -08:00
Yusuke Tsutsumi
c99ecc511f gcp_storage_object asserts for dest on upload
The `dest` field is required for upload and delete. This was not
explicitly documented nor asserted.

Fixes #235.
2023-02-03 16:48:55 -08:00
nkakouros
30c2bbd84e Fixes GcpRequest comparison for boolean parameters
Fixes #402 .
2023-01-23 14:33:26 -08:00
S. Shuck
226ec3dd3f Improve error handling for auth_kind 'serviceaccount'
Fixes ansible-collections/google.cloud#538.
2022-12-29 12:59:12 -08:00
Yusuke Tsutsumi
0ed49af7df re-add gcp_compute as a valid plugin name
commit ccbde5f93e introduced
a backwards-incompatible change which made ansible-inventory
no longer recognize `gcp_compute` as a valid package name.

This would break users who are use `gcp_compute` (instead of the
new `google.cloud.gcp_compute`). Accepting both until at least
a major version change.

fixes #536.
2022-12-21 09:34:56 -08:00
Yusuke Tsutsumi
509e0207ff tests: add sanity tests for python 2.7
Automation Hub still runs sanity tests on python 2.7

updating release to 1.1.1 to publish a new version.
2022-12-16 09:40:24 -08:00
Yusuke Tsutsumi
2db181d084 fix gcp_iam_role not updating
gcp_iam_role was not updating previously. The API uses a PATCH and
not a PUT.

Also fixing an accidental leftover diff from a bad merge.

fixes #236.
2022-12-15 23:04:47 -08:00
Yusuke Tsutsumi
d063d44b73 fixing gcp_resourcemanager_project delete
gcp_resourcemanager_project was not properly deleting projects.

fixing gcp_resourcemanager_project as well.

fixes #530.
2022-12-12 22:25:24 -08:00
Yusuke Tsutsumi
a9545c77a4 fix linting and updating maintenance guide
Updating the maintainers guide with updated intructions from
Ansible engineers.

Fixing linting issues, and adding the linter as a GitHub workflow
to ensure there are no regressions.
2022-12-07 15:36:21 -08:00
Rebecca Peterson
21c9479ece Update gcp_filestore_instance.py
`filestore/docs/accessing-fileshares` has been removed and replaced with `filestore/docs/csi-driver`
2022-12-02 10:20:13 -08:00
Andrew Dolgov
32e7eea25f Rename base_domain to name_suffix, make adjustments based on PR feedback 2022-11-28 21:59:00 -08:00