From 5cd0e2f19f0e592897c23a515a4750a3bf1bd569 Mon Sep 17 00:00:00 2001 From: The Magician Date: Fri, 12 Jul 2019 12:08:09 -0700 Subject: [PATCH] Bug fixes for GCP modules (#58900) --- lib/ansible/module_utils/gcp_utils.py | 19 ++++++++++++++----- lib/ansible/plugins/doc_fragments/gcp.py | 14 ++++++++++---- .../gcp_bigquery_dataset/tasks/main.yml | 6 ++---- .../targets/gcp_bigquery_table/tasks/main.yml | 6 ++---- .../gcp_compute_address/tasks/main.yml | 2 -- .../gcp_compute_backend_bucket/tasks/main.yml | 2 -- .../tasks/main.yml | 2 -- .../targets/gcp_compute_disk/tasks/main.yml | 2 -- .../gcp_compute_firewall/tasks/main.yml | 2 -- .../tasks/main.yml | 2 -- .../gcp_compute_global_address/tasks/main.yml | 2 -- 11 files changed, 28 insertions(+), 31 deletions(-) diff --git a/lib/ansible/module_utils/gcp_utils.py b/lib/ansible/module_utils/gcp_utils.py index d2f9b01afe9..d08298b3007 100644 --- a/lib/ansible/module_utils/gcp_utils.py +++ b/lib/ansible/module_utils/gcp_utils.py @@ -165,9 +165,14 @@ class GcpSession(object): self.module.fail_json(msg="Credential type '%s' not implemented" % cred_type) def _headers(self): - return { - 'User-Agent': "Google-Ansible-MM-{0}".format(self.product) - } + if self.module.params.get('env_type'): + return { + 'User-Agent': "Google-Ansible-MM-{0}-{1}".format(self.product, self.module.params.get('env_type')) + } + else: + return { + 'User-Agent': "Google-Ansible-MM-{0}".format(self.product) + } def _merge_dictionaries(self, a, b): new = a.copy() @@ -189,7 +194,7 @@ class GcpModule(AnsibleModule): type='str', fallback=(env_fallback, ['GCP_PROJECT'])), auth_kind=dict( - required=False, + required=True, fallback=(env_fallback, ['GCP_AUTH_KIND']), choices=['machineaccount', 'serviceaccount', 'application'], type='str'), @@ -208,7 +213,11 @@ class GcpModule(AnsibleModule): scopes=dict( required=False, fallback=(env_fallback, ['GCP_SCOPES']), - type='list') + type='list'), + env_type=dict( + required=False, + fallback=(env_fallback, ['GCP_ENV_TYPE']), + type='str') ) ) diff --git a/lib/ansible/plugins/doc_fragments/gcp.py b/lib/ansible/plugins/doc_fragments/gcp.py index 110d2795958..60a98d054b5 100644 --- a/lib/ansible/plugins/doc_fragments/gcp.py +++ b/lib/ansible/plugins/doc_fragments/gcp.py @@ -37,13 +37,19 @@ options: description: - Array of scopes to be used. type: list + env_type: + description: + - Specifies which Ansible environment you're running this module within. + - This should not be set unless you know what you're doing. + - This only alters the User Agent string for any API requests. + type: str notes: - - For authentication, you can set service_account_file using the - C(GCP_SERVICE_ACCOUNT_FILE) env variable. + - for authentication, you can set service_account_file using the + c(gcp_service_account_file) env variable. + - for authentication, you can set service_account_contents using the + c(GCP_SERVICE_ACCOUNT_CONTENTS) env variable. - For authentication, you can set service_account_email using the C(GCP_SERVICE_ACCOUNT_EMAIL) env variable. - - For authentication, you can set service_account_contents using the - C(GCP_SERVICE_ACCOUNT_CONTENTS) env variable. - For authentication, you can set auth_kind using the C(GCP_AUTH_KIND) env variable. - For authentication, you can set scopes using the C(GCP_SCOPES) env variable. diff --git a/test/integration/targets/gcp_bigquery_dataset/tasks/main.yml b/test/integration/targets/gcp_bigquery_dataset/tasks/main.yml index 609caf1c43e..0eba0b4e5f1 100644 --- a/test/integration/targets/gcp_bigquery_dataset/tasks/main.yml +++ b/test/integration/targets/gcp_bigquery_dataset/tasks/main.yml @@ -49,7 +49,7 @@ - name: verify that command succeeded assert: that: - - results['resources'] | map(attribute='name') | select("match", ".*my_example_dataset.*") | list | length == 1 + - results['resources'] | map(attribute='datasetReference') | map(attribute='datasetId') | select("match", ".*my_example_dataset.*") | list | length == 1 # ---------------------------------------------------------------------------- - name: create a dataset that already exists gcp_bigquery_dataset: @@ -81,7 +81,6 @@ assert: that: - result.changed == true - - result.has_key('kind') == False - name: verify that dataset was deleted gcp_bigquery_dataset_facts: project: "{{ gcp_project }}" @@ -93,7 +92,7 @@ - name: verify that command succeeded assert: that: - - results['resources'] | map(attribute='name') | select("match", ".*my_example_dataset.*") | list | length == 0 + - results['resources'] | map(attribute='datasetReference') | map(attribute='datasetId') | select("match", ".*my_example_dataset.*") | list | length == 0 # ---------------------------------------------------------------------------- - name: delete a dataset that does not exist gcp_bigquery_dataset: @@ -109,4 +108,3 @@ assert: that: - result.changed == false - - result.has_key('kind') == False diff --git a/test/integration/targets/gcp_bigquery_table/tasks/main.yml b/test/integration/targets/gcp_bigquery_table/tasks/main.yml index a06a71b8e95..8d454099ddb 100644 --- a/test/integration/targets/gcp_bigquery_table/tasks/main.yml +++ b/test/integration/targets/gcp_bigquery_table/tasks/main.yml @@ -66,7 +66,7 @@ - name: verify that command succeeded assert: that: - - results['resources'] | map(attribute='name') | select("match", ".*example_table.*") | list | length == 1 + - results['resources'] | map(attribute='tableReference') | map(attribute='tableId') | select("match", ".*example_table.*") | list | length == 1 # ---------------------------------------------------------------------------- - name: create a table that already exists gcp_bigquery_table: @@ -104,7 +104,6 @@ assert: that: - result.changed == true - - result.has_key('kind') == False - name: verify that table was deleted gcp_bigquery_table_facts: dataset: example_dataset @@ -117,7 +116,7 @@ - name: verify that command succeeded assert: that: - - results['resources'] | map(attribute='name') | select("match", ".*example_table.*") | list | length == 0 + - results['resources'] | map(attribute='tableReference') | map(attribute='tableId') | select("match", ".*example_table.*") | list | length == 0 # ---------------------------------------------------------------------------- - name: delete a table that does not exist gcp_bigquery_table: @@ -136,7 +135,6 @@ assert: that: - result.changed == false - - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown # If errors happen, don't crash the playbook! diff --git a/test/integration/targets/gcp_compute_address/tasks/main.yml b/test/integration/targets/gcp_compute_address/tasks/main.yml index 0bffaf6e2f1..71631237a43 100644 --- a/test/integration/targets/gcp_compute_address/tasks/main.yml +++ b/test/integration/targets/gcp_compute_address/tasks/main.yml @@ -80,7 +80,6 @@ assert: that: - result.changed == true - - result.has_key('kind') == False - name: verify that address was deleted gcp_compute_address_facts: filters: @@ -110,4 +109,3 @@ assert: that: - result.changed == false - - result.has_key('kind') == False diff --git a/test/integration/targets/gcp_compute_backend_bucket/tasks/main.yml b/test/integration/targets/gcp_compute_backend_bucket/tasks/main.yml index fe5a58a334a..35c452d8dd5 100644 --- a/test/integration/targets/gcp_compute_backend_bucket/tasks/main.yml +++ b/test/integration/targets/gcp_compute_backend_bucket/tasks/main.yml @@ -95,7 +95,6 @@ assert: that: - result.changed == true - - result.has_key('kind') == False - name: verify that backend_bucket was deleted gcp_compute_backend_bucket_facts: filters: @@ -126,7 +125,6 @@ assert: that: - result.changed == false - - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown # If errors happen, don't crash the playbook! diff --git a/test/integration/targets/gcp_compute_backend_service/tasks/main.yml b/test/integration/targets/gcp_compute_backend_service/tasks/main.yml index 5b69756e126..8e49959e1bd 100644 --- a/test/integration/targets/gcp_compute_backend_service/tasks/main.yml +++ b/test/integration/targets/gcp_compute_backend_service/tasks/main.yml @@ -116,7 +116,6 @@ assert: that: - result.changed == true - - result.has_key('kind') == False - name: verify that backend_service was deleted gcp_compute_backend_service_facts: filters: @@ -149,7 +148,6 @@ assert: that: - result.changed == false - - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown # If errors happen, don't crash the playbook! diff --git a/test/integration/targets/gcp_compute_disk/tasks/main.yml b/test/integration/targets/gcp_compute_disk/tasks/main.yml index 778b5e757cb..bc524b14f05 100644 --- a/test/integration/targets/gcp_compute_disk/tasks/main.yml +++ b/test/integration/targets/gcp_compute_disk/tasks/main.yml @@ -92,7 +92,6 @@ assert: that: - result.changed == true - - result.has_key('kind') == False - name: verify that disk was deleted gcp_compute_disk_facts: filters: @@ -125,4 +124,3 @@ assert: that: - result.changed == false - - result.has_key('kind') == False diff --git a/test/integration/targets/gcp_compute_firewall/tasks/main.yml b/test/integration/targets/gcp_compute_firewall/tasks/main.yml index 6e3b4ef1627..b58e1fde0c0 100644 --- a/test/integration/targets/gcp_compute_firewall/tasks/main.yml +++ b/test/integration/targets/gcp_compute_firewall/tasks/main.yml @@ -111,7 +111,6 @@ assert: that: - result.changed == true - - result.has_key('kind') == False - name: verify that firewall was deleted gcp_compute_firewall_facts: filters: @@ -148,4 +147,3 @@ assert: that: - result.changed == false - - result.has_key('kind') == False diff --git a/test/integration/targets/gcp_compute_forwarding_rule/tasks/main.yml b/test/integration/targets/gcp_compute_forwarding_rule/tasks/main.yml index 565279ffccc..facd4daaa05 100644 --- a/test/integration/targets/gcp_compute_forwarding_rule/tasks/main.yml +++ b/test/integration/targets/gcp_compute_forwarding_rule/tasks/main.yml @@ -114,7 +114,6 @@ assert: that: - result.changed == true - - result.has_key('kind') == False - name: verify that forwarding_rule was deleted gcp_compute_forwarding_rule_facts: filters: @@ -148,7 +147,6 @@ assert: that: - result.changed == false - - result.has_key('kind') == False #--------------------------------------------------------- # Post-test teardown # If errors happen, don't crash the playbook! diff --git a/test/integration/targets/gcp_compute_global_address/tasks/main.yml b/test/integration/targets/gcp_compute_global_address/tasks/main.yml index fa633dcd00f..c0cc1097f6c 100644 --- a/test/integration/targets/gcp_compute_global_address/tasks/main.yml +++ b/test/integration/targets/gcp_compute_global_address/tasks/main.yml @@ -75,7 +75,6 @@ assert: that: - result.changed == true - - result.has_key('kind') == False - name: verify that global_address was deleted gcp_compute_global_address_facts: filters: @@ -103,4 +102,3 @@ assert: that: - result.changed == false - - result.has_key('kind') == False