From 4b2841344623e3de51a17ec7a24e13508267f950 Mon Sep 17 00:00:00 2001 From: Paul Puschmann Date: Wed, 10 Apr 2019 18:50:06 +0200 Subject: [PATCH] Backport/2.7/50183 (#55035) * gcp: documentation update (#50183) Signed-off-by: Abhijeet Kasurde (cherry picked from commit ae404d1476c621d26662b9eb6ab0d148b465b998) * Add changelog-document for gcp_inventory improvement --- .../fragments/50183-improve-gcp-documentation.yaml | 2 ++ docs/docsite/rst/scenario_guides/guide_gce.rst | 14 +++++++++++--- lib/ansible/module_utils/gcp_utils.py | 8 ++++---- 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/50183-improve-gcp-documentation.yaml diff --git a/changelogs/fragments/50183-improve-gcp-documentation.yaml b/changelogs/fragments/50183-improve-gcp-documentation.yaml new file mode 100644 index 00000000000..b164b6f8ed3 --- /dev/null +++ b/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 diff --git a/docs/docsite/rst/scenario_guides/guide_gce.rst b/docs/docsite/rst/scenario_guides/guide_gce.rst index 77a1715472c..b585fead4bf 100644 --- a/docs/docsite/rst/scenario_guides/guide_gce.rst +++ b/docs/docsite/rst/scenario_guides/guide_gce.rst @@ -121,8 +121,16 @@ 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: @@ -130,7 +138,7 @@ Here's an example of a valid inventory file: plugin: gcp_compute projects: - - google.com:graphite-playground + - graphite-playground filters: auth_kind: serviceaccount service_account_file: /home/alexstephen/my_account.json diff --git a/lib/ansible/module_utils/gcp_utils.py b/lib/ansible/module_utils/gcp_utils.py index 1fbd07c2527..8bb7a8263d4 100644 --- a/lib/ansible/module_utils/gcp_utils.py +++ b/lib/ansible/module_utils/gcp_utils.py @@ -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 @@ -114,12 +114,12 @@ class GcpSession(object): 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): @@ -134,7 +134,7 @@ class GcpSession(object): 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 {