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