Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not try to encode metadata if it is None #46739

Merged
merged 3 commits into from Oct 10, 2018

Conversation

thpica
Copy link
Contributor

@thpica thpica commented Oct 10, 2018

SUMMARY

In the gcp_compute_instance module, when not specifying the metadata key or leaving it undefined, it crashes trying to iterate on a None here: https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/google/gcp_compute_instance.py#L1138

This PR addresses it by skipping the call to metadata_encoder() if request['metadata'] is None.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

gcp_compute_instance

ANSIBLE VERSION
ansible 2.7.0.post0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/tpicariello/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/tpicariello/.pyenv/batcheval/local/lib/python2.7/site-packages/ansible
  executable location = /home/tpicariello/.pyenv/project/bin/ansible
  python version = 2.7.12 (default, Jul 18 2016, 15:02:52) [GCC 4.8.4]
ADDITIONAL INFORMATION

Omitting the metadata key in the example given by the doc allows to reproduce the issue:

- name: create a instance
  gcp_compute_instance:
      name: "test_object"
      machine_type: n1-standard-1
      disks:
      - auto_delete: true
        boot: true
        source: "{{ disk }}"
      network_interfaces:
      - network: "{{ network }}"
        access_configs:
        - name: External NAT
          nat_ip: "{{ address }}"
          type: ONE_TO_ONE_NAT
      zone: us-central1-a
      project: "test_project"
      auth_kind: "service_account"
      service_account_file: "/tmp/auth.pem"
      state: present

Reopening #46491 on devel

@mkrizek
Copy link
Contributor

mkrizek commented Oct 10, 2018

This looks good. Please add a changelog fragment as mentioned in #46491 (comment). Thanks!

@ansibot
Copy link
Contributor

ansibot commented Oct 10, 2018

@thpica: thank you for submitting this pull-request!

cc @erjohnso @rambleraptor
click here for bot help

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. cloud community_review In order to be merged, this PR must follow the community review workflow. gce module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community. labels Oct 10, 2018
@mkrizek mkrizek merged commit 62d1317 into ansible:devel Oct 10, 2018
Tomorrow9 pushed a commit to Tomorrow9/ansible that referenced this pull request Dec 4, 2018
* Do not try to encode metadata if it is None

* Add changelog fragment

* Fix fragment missing EOF line
thpica added a commit to thpica/ansible that referenced this pull request Dec 11, 2018
* Do not try to encode metadata if it is None

* Add changelog fragment

* Fix fragment missing EOF line
abadger pushed a commit that referenced this pull request Jan 7, 2019
* Do not try to encode metadata if it is None

* Add changelog fragment

* Fix fragment missing EOF line
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. cloud community_review In order to be merged, this PR must follow the community review workflow. gce module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants