From 1705ef5f263c81c6c8edf5d6beb31b083a8522fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Moser?= Date: Tue, 23 Apr 2019 21:22:17 +0200 Subject: [PATCH] vultr_server: fix idempotency for private network and IPv6 options (#55619) * vultr_server: fix idempotency for private network and IPv6 options * add changelog --- .../fragments/55619-vultr_server_idempotency.yml | 2 ++ lib/ansible/module_utils/vultr.py | 10 +++++----- .../targets/vultr_server/tasks/main.yml | 15 +++++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/55619-vultr_server_idempotency.yml diff --git a/changelogs/fragments/55619-vultr_server_idempotency.yml b/changelogs/fragments/55619-vultr_server_idempotency.yml new file mode 100644 index 0000000000..0189b684d3 --- /dev/null +++ b/changelogs/fragments/55619-vultr_server_idempotency.yml @@ -0,0 +1,2 @@ +bugfixes: + - vultr_server - Fix idempotency for options ``ipv6_enabled`` and ``private_network_enabled``. diff --git a/lib/ansible/module_utils/vultr.py b/lib/ansible/module_utils/vultr.py index 83cf55582f..af4a333f3a 100644 --- a/lib/ansible/module_utils/vultr.py +++ b/lib/ansible/module_utils/vultr.py @@ -128,15 +128,15 @@ class Vultr: return r_value = resource.get(resource_key) - if isinstance(param, bool): - if param is True and r_value not in ['yes', 'enable']: + if r_value in ['yes', 'no']: + if param and r_value != 'yes': return "enable" - elif param is False and r_value not in ['no', 'disable']: + elif not param and r_value != 'no': return "disable" else: - if r_value is None: + if param and not r_value: return "enable" - else: + elif not param and r_value: return "disable" def api_query(self, path="/", method="GET", data=None): diff --git a/test/integration/targets/vultr_server/tasks/main.yml b/test/integration/targets/vultr_server/tasks/main.yml index c0a5a5c73c..9058b73431 100644 --- a/test/integration/targets/vultr_server/tasks/main.yml +++ b/test/integration/targets/vultr_server/tasks/main.yml @@ -313,6 +313,7 @@ os: CentOS 6 x64 plan: "{{ vultr_server_plan_2 }}" auto_backup_enabled: yes + private_network_enabled: yes region: Amsterdam force: yes register: result @@ -327,6 +328,7 @@ - result.vultr_server.plan == vultr_server_plan_1 - result.vultr_server.region == 'Amsterdam' - result.vultr_server.auto_backup_enabled == false + - result.vultr_server.internal_ip == '' - name: test update server with force vultr_server: @@ -334,6 +336,7 @@ os: CentOS 6 x64 plan: "{{ vultr_server_plan_2 }}" auto_backup_enabled: yes + private_network_enabled: yes region: Amsterdam force: yes register: result @@ -347,15 +350,17 @@ - result.vultr_server.plan == vultr_server_plan_2 - result.vultr_server.region == 'Amsterdam' - result.vultr_server.auto_backup_enabled == true + - result.vultr_server.internal_ip != '' - name: test update server idempotence with force vultr_server: name: "{{ vultr_server_name }}" os: CentOS 6 x64 plan: "{{ vultr_server_plan_2 }}" - auto_backup_enabled: true + auto_backup_enabled: yes + private_network_enabled: yes region: Amsterdam - force: true + force: yes register: result - name: verify test update server idempotence with force assert: @@ -367,13 +372,14 @@ - result.vultr_server.plan == vultr_server_plan_2 - result.vultr_server.region == 'Amsterdam' - result.vultr_server.auto_backup_enabled == true + - result.vultr_server.internal_ip != '' - name: test update server to stopped in check mode vultr_server: name: "{{ vultr_server_name }}" os: CentOS 6 x64 plan: "{{ vultr_server_plan_2 }}" - ipv6_enabled: true + ipv6_enabled: yes region: Amsterdam state: stopped register: result @@ -394,7 +400,7 @@ name: "{{ vultr_server_name }}" os: CentOS 6 x64 plan: "{{ vultr_server_plan_2 }}" - ipv6_enabled: true + ipv6_enabled: yes region: Amsterdam state: stopped register: result @@ -414,6 +420,7 @@ name: "{{ vultr_server_name }}" os: CentOS 6 x64 plan: "{{ vultr_server_plan_2 }}" + ipv6_enabled: yes region: Amsterdam state: stopped register: result