summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Moser <mail@renemoser.net>2018-11-04 11:23:36 +0100
committerGitHub <noreply@github.com>2018-11-04 11:23:36 +0100
commit788247583b9bdfaf24984a207e8495bb402c790c (patch)
tree090c023996c8197d1ea76f23429044f77e3b0034
parent435e764fb3d2b1f3222c6f0fc2df18d01a3d4eb1 (diff)
downloadansible-788247583b9bdfaf24984a207e8495bb402c790c.tar.gz
vultr: fix for API returned unexpected empty list (#48036)
* vultr: fix for API returned unexpected empty list * add changelog
-rw-r--r--changelogs/fragments/48036-vultr-fix-empty-list-handling.yaml3
-rw-r--r--lib/ansible/module_utils/vultr.py2
-rw-r--r--test/legacy/roles/vultr_server_facts/tasks/main.yml15
3 files changed, 19 insertions, 1 deletions
diff --git a/changelogs/fragments/48036-vultr-fix-empty-list-handling.yaml b/changelogs/fragments/48036-vultr-fix-empty-list-handling.yaml
new file mode 100644
index 0000000000..5d97d48e6a
--- /dev/null
+++ b/changelogs/fragments/48036-vultr-fix-empty-list-handling.yaml
@@ -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.
diff --git a/lib/ansible/module_utils/vultr.py b/lib/ansible/module_utils/vultr.py
index 775c970a59..83cf55582f 100644
--- a/lib/ansible/module_utils/vultr.py
+++ b/lib/ansible/module_utils/vultr.py
@@ -201,7 +201,7 @@ class Vultr:
return {}
try:
- return self.module.from_json(to_text(res))
+ return self.module.from_json(to_native(res)) or {}
except ValueError as e:
self.module.fail_json(msg="Could not process response into json: %s" % e)
diff --git a/test/legacy/roles/vultr_server_facts/tasks/main.yml b/test/legacy/roles/vultr_server_facts/tasks/main.yml
index 149ed1bf40..f60d0c6d7c 100644
--- a/test/legacy/roles/vultr_server_facts/tasks/main.yml
+++ b/test/legacy/roles/vultr_server_facts/tasks/main.yml
@@ -1,8 +1,23 @@
# 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)
---
+- 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
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
vultr_server: