Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport/2.7/50183 #55035

Merged
merged 2 commits into from Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/50183-improve-gcp-documentation.yaml
@@ -0,0 +1,2 @@
bugfixes:
- gcp_compute - improve documentation on the usage of the dynamics gcp_compute inventory
14 changes: 11 additions & 3 deletions docs/docsite/rst/scenario_guides/guide_gce.rst
Expand Up @@ -121,16 +121,24 @@ GCE Dynamic Inventory

The best way to interact with your hosts is to use the gcp_compute inventory plugin, which dynamically queries GCE and tells Ansible what nodes can be managed.

To use the gcp_compute inventory plugin, create a file that ends in .gcp.yml file in your root directory. The gcp_compute inventory script takes in the same authentication
information as any module.
To be able to use this GCE dynamic inventory plugin, you need to enable it first by specifying the following in the ``ansible.cfg`` file:

.. code-block:: ini

[inventory]
enable_plugins = gcp_compute

Then, create a file that ends in ``.gcp.yml`` in your root directory.

The gcp_compute inventory script takes in the same authentication information as any module.

Here's an example of a valid inventory file:

.. code-block:: yaml

plugin: gcp_compute
projects:
- google.com:graphite-playground
- graphite-playground
filters:
auth_kind: serviceaccount
service_account_file: /home/alexstephen/my_account.json
Expand Down
8 changes: 4 additions & 4 deletions lib/ansible/module_utils/gcp_utils.py
Expand Up @@ -63,7 +63,7 @@ def replace_resource_dict(item, value):
return item.get(value)


# Handles all authentation and HTTP sessions for GCP API calls.
# Handles all authentication and HTTP sessions for GCP API calls.
class GcpSession(object):
def __init__(self, module, product):
self.module = module
Expand Down Expand Up @@ -114,12 +114,12 @@ def _validate(self):

if self.module.params.get('service_account_email') is not None and self.module.params['auth_kind'] != 'machineaccount':
self.module.fail_json(
msg="Service Acccount Email only works with Machine Account-based authentication"
msg="Service Account Email only works with Machine Account-based authentication"
)

if self.module.params.get('service_account_file') is not None and self.module.params['auth_kind'] != 'serviceaccount':
self.module.fail_json(
msg="Service Acccount File only works with Service Account-based authentication"
msg="Service Account File only works with Service Account-based authentication"
)

def _credentials(self):
Expand All @@ -134,7 +134,7 @@ def _credentials(self):
return google.auth.compute_engine.Credentials(
self.module.params['service_account_email'])
else:
self.module.fail_json(msg="Credential type '%s' not implmented" % cred_type)
self.module.fail_json(msg="Credential type '%s' not implemented" % cred_type)

def _headers(self):
return {
Expand Down