From ab26119637554b3f490c6a9bf6e528a1fad6a36c Mon Sep 17 00:00:00 2001 From: Christian Kotte Date: Thu, 4 Oct 2018 12:27:33 +0200 Subject: [PATCH] VMware: Add check mode support to module vmware_host_acceptance (#46260) * Improve module description * Add check mode support --- .../cloud/vmware/vmware_host_acceptance.py | 13 +++++++++---- .../vmware_host_acceptance/tasks/main.yml | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_host_acceptance.py b/lib/ansible/modules/cloud/vmware/vmware_host_acceptance.py index dc6984a7922..31afc57ee80 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_host_acceptance.py +++ b/lib/ansible/modules/cloud/vmware/vmware_host_acceptance.py @@ -17,9 +17,10 @@ ANSIBLE_METADATA = { DOCUMENTATION = r''' --- module: vmware_host_acceptance -short_description: Manage acceptance level of ESXi host +short_description: Manage the host acceptance level of an ESXi host description: -- This module can be used to manage acceptance level of an ESXi host. +- This module can be used to manage the host acceptance level of an ESXi host. +- The host acceptance level controls the acceptance level of each VIB on a ESXi host. version_added: '2.5' author: - Abhijeet Kasurde (@Akasurde) @@ -139,9 +140,12 @@ class VMwareAccpetanceManager(PyVmomi): host_image_config_mgr = host.configManager.imageConfigManager if host_image_config_mgr: try: - host_image_config_mgr.UpdateHostImageAcceptanceLevel(newAcceptanceLevel=self.acceptance_level) + if self.module.check_mode: + self.hosts_facts[host.name]['level'] = self.acceptance_level + else: + host_image_config_mgr.UpdateHostImageAcceptanceLevel(newAcceptanceLevel=self.acceptance_level) + self.hosts_facts[host.name]['level'] = host_image_config_mgr.HostImageConfigGetAcceptance() host_changed = True - self.hosts_facts[host.name]['level'] = host_image_config_mgr.HostImageConfigGetAcceptance() except vim.fault.HostConfigFault as e: self.hosts_facts[host.name]['error'] = to_native(e.msg) @@ -176,6 +180,7 @@ def main(): required_if=[ ['state', 'present', ['acceptance_level']], ], + supports_check_mode=True ) vmware_host_accept_config = VMwareAccpetanceManager(module) diff --git a/test/integration/targets/vmware_host_acceptance/tasks/main.yml b/test/integration/targets/vmware_host_acceptance/tasks/main.yml index 4912b0e12ab..816866564ab 100644 --- a/test/integration/targets/vmware_host_acceptance/tasks/main.yml +++ b/test/integration/targets/vmware_host_acceptance/tasks/main.yml @@ -61,3 +61,21 @@ - assert: that: - host_acceptance_facts.facts is defined + +- name: Change acceptance level of given hosts in check mode + vmware_host_acceptance: + hostname: "{{ vcsim }}" + username: "{{ user }}" + password: "{{ passwd }}" + esxi_hostname: "{{ host1 }}" + validate_certs: no + acceptance_level: vmware_certified + state: present + register: host_acceptance_facts_check_mode + check_mode: yes + +- debug: var=host_acceptance_facts_check_mode + +- assert: + that: + - host_acceptance_facts_check_mode.facts is defined