From ccfa6ff0116ae8f7c403565f340228af29ce9ad5 Mon Sep 17 00:00:00 2001 From: Christian Kotte Date: Mon, 8 Oct 2018 11:41:52 +0200 Subject: [PATCH] VMware: Add check mode support to module vmware_host_ntp (#46268) --- .../modules/cloud/vmware/vmware_host_ntp.py | 10 +- .../targets/vmware_host_ntp/tasks/main.yml | 97 +++++++++++++++++++ 2 files changed, 104 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_host_ntp.py b/lib/ansible/modules/cloud/vmware/vmware_host_ntp.py index 962e9ec005f..7d4d4e3af4a 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_host_ntp.py +++ b/lib/ansible/modules/cloud/vmware/vmware_host_ntp.py @@ -131,8 +131,11 @@ class VmwareNtpConfigManager(PyVmomi): date_config_spec = vim.host.DateTimeConfig() date_config_spec.ntpConfig = ntp_config_spec try: - host_date_time_manager.UpdateDateTimeConfig(date_config_spec) - self.results[host.name]['after_change_ntp_servers'] = host_date_time_manager.dateTimeInfo.ntpConfig.server + if self.module.check_mode: + self.results[host.name]['after_change_ntp_servers'] = available_ntp_servers + else: + host_date_time_manager.UpdateDateTimeConfig(date_config_spec) + self.results[host.name]['after_change_ntp_servers'] = host_date_time_manager.dateTimeInfo.ntpConfig.server changed = True except vim.fault.HostConfigFault as e: self.results[host.name]['error'] = to_native(e.msg) @@ -195,7 +198,8 @@ def main(): argument_spec=argument_spec, required_one_of=[ ['cluster_name', 'esxi_hostname'], - ] + ], + supports_check_mode=True ) vmware_host_ntp_config = VmwareNtpConfigManager(module) diff --git a/test/integration/targets/vmware_host_ntp/tasks/main.yml b/test/integration/targets/vmware_host_ntp/tasks/main.yml index bc8053f90f2..d780b977d7d 100644 --- a/test/integration/targets/vmware_host_ntp/tasks/main.yml +++ b/test/integration/targets/vmware_host_ntp/tasks/main.yml @@ -145,3 +145,100 @@ register: present - debug: var=present + +- name: Change facts about all hosts in given cluster in check mode + vmware_host_ntp: + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + esxi_hostname: "{{ host1 }}" + state: present + ntp_server: + - 0.pool.ntp.org + validate_certs: no + register: present + check_mode: yes + +- debug: var=present + +- name: Change facts about all hosts in given cluster in check mode + vmware_host_ntp: + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + esxi_hostname: "{{ host1 }}" + state: present + ntp_server: + - 1.pool.ntp.org + validate_certs: no + register: present + check_mode: yes + +- debug: var=present + +- name: Change facts about all hosts in given cluster in check mode + vmware_host_ntp: + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + esxi_hostname: "{{ host1 }}" + state: absent + ntp_server: + - 1.pool.ntp.org + validate_certs: no + register: present + check_mode: yes + +- debug: var=present + +- name: Change facts about all hosts in given cluster in check mode + vmware_host_ntp: + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + esxi_hostname: "{{ host1 }}" + state: present + ntp_server: + - 1.pool.ntp.org + validate_certs: no + register: present + check_mode: yes + +- debug: var=present + +- name: Change facts about all hosts in given cluster in check mode + vmware_host_ntp: + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + esxi_hostname: "{{ host1 }}" + state: present + ntp_server: + - 2.pool.ntp.org + - 3.pool.ntp.org + - 4.pool.ntp.org + validate_certs: no + register: present + check_mode: yes + +- debug: var=present + +- name: Change facts about all hosts in given cluster in check mode + vmware_host_ntp: + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + esxi_hostname: "{{ host1 }}" + state: absent + ntp_server: + - 0.pool.ntp.org + - 1.pool.ntp.org + - 2.pool.ntp.org + - 3.pool.ntp.org + - 4.pool.ntp.org + - 6.pool.ntp.org + validate_certs: no + register: present + check_mode: yes + +- debug: var=present