vultr: fix for API returned unexpected empty list (#48036)

* vultr: fix for API returned unexpected empty list

* add changelog

(cherry picked from commit 788247583b)
This commit is contained in:
René Moser 2018-11-04 11:23:36 +01:00 committed by Toshio Kuratomi
parent 90fe1be33a
commit b000c1633d
3 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1,3 @@
bugfixes:
- vultr - fixed the handling of an inconsistency in the response from
Vultr API when it returns an unexpected empty list instead a empty dict.

View file

@ -201,7 +201,7 @@ class Vultr:
return {} return {}
try: try:
return self.module.from_json(to_text(res)) return self.module.from_json(to_native(res)) or {}
except ValueError as e: except ValueError as e:
self.module.fail_json(msg="Could not process response into json: %s" % e) self.module.fail_json(msg="Could not process response into json: %s" % e)

View file

@ -1,8 +1,23 @@
# Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org> # Copyright (c) 2018, Yanis Guenane <yanis+ansible@guenane.org>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
--- ---
- name: setup ensure VM is absent
vultr_server:
name: "{{ vultr_server_name }}"
state: absent
register: result
# Servers can only be destroyed 5 min after creation
- name: wait for 5 min until VM is absent
local_action: wait_for
when: result is changed
- name: test gather vultr server facts - empty resources - name: test gather vultr server facts - empty resources
vultr_server_facts: vultr_server_facts:
- name: verify test gather vultr server facts - empty resources
assert:
that:
- ansible_facts.vultr_server_facts | count == 0
- name: Create the server - name: Create the server
vultr_server: vultr_server: