gcp: documentation update (#50183)

* gcp: documentation update

* Update example about dynamic inventory
* minor typo fixes in gcp_utils
* Additional information about enabling inventory plugin in ansible.cfg

partially fixes: #44404

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/50498/head
Abhijeet Kasurde 6 years ago committed by Sandra McCann
parent a45063defe
commit ae404d1476

@ -127,8 +127,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. 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 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:
information as any module.
.. 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: Here's an example of a valid inventory file:
@ -136,7 +144,7 @@ Here's an example of a valid inventory file:
plugin: gcp_compute plugin: gcp_compute
projects: projects:
- google.com:graphite-playground - graphite-playground
filters: filters:
auth_kind: serviceaccount auth_kind: serviceaccount
service_account_file: /home/alexstephen/my_account.json service_account_file: /home/alexstephen/my_account.json

@ -63,7 +63,7 @@ def replace_resource_dict(item, value):
return item.get(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): class GcpSession(object):
def __init__(self, module, product): def __init__(self, module, product):
self.module = module 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': if self.module.params.get('service_account_email') is not None and self.module.params['auth_kind'] != 'machineaccount':
self.module.fail_json( 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': if self.module.params.get('service_account_file') is not None and self.module.params['auth_kind'] != 'serviceaccount':
self.module.fail_json( 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): def _credentials(self):
@ -134,7 +134,7 @@ class GcpSession(object):
return google.auth.compute_engine.Credentials( return google.auth.compute_engine.Credentials(
self.module.params['service_account_email']) self.module.params['service_account_email'])
else: 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): def _headers(self):
return { return {

Loading…
Cancel
Save