From 62d131716b6fac64a53cc4b40076e370331445de Mon Sep 17 00:00:00 2001 From: Thomas Picariello Date: Wed, 10 Oct 2018 12:14:47 +0200 Subject: [PATCH] Do not try to encode metadata if it is None (#46739) * Do not try to encode metadata if it is None * Add changelog fragment * Fix fragment missing EOF line --- changelogs/fragments/46739-gcp-compute-instance-metadata.yaml | 2 ++ lib/ansible/modules/cloud/google/gcp_compute_instance.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/46739-gcp-compute-instance-metadata.yaml diff --git a/changelogs/fragments/46739-gcp-compute-instance-metadata.yaml b/changelogs/fragments/46739-gcp-compute-instance-metadata.yaml new file mode 100644 index 0000000000..73cbeb1649 --- /dev/null +++ b/changelogs/fragments/46739-gcp-compute-instance-metadata.yaml @@ -0,0 +1,2 @@ +bugfixes: + - "gcp_compute_instance - fix crash when the instance metadata is not set" diff --git a/lib/ansible/modules/cloud/google/gcp_compute_instance.py b/lib/ansible/modules/cloud/google/gcp_compute_instance.py index e4140516cb..5ac79538a3 100644 --- a/lib/ansible/modules/cloud/google/gcp_compute_instance.py +++ b/lib/ansible/modules/cloud/google/gcp_compute_instance.py @@ -1106,7 +1106,7 @@ def raise_if_errors(response, err_path, module): def encode_request(request, module): - if 'metadata' in request: + if 'metadata' in request and request['metadata'] is not None: request['metadata'] = metadata_encoder(request['metadata']) return request