1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

VMware: Add check mode support to module vmware_host_service_manager (#46271)

This commit is contained in:
Christian Kotte 2018-10-08 11:39:38 +02:00 committed by Abhijeet Kasurde
parent 77127d6768
commit c4cfeb183f
2 changed files with 46 additions and 7 deletions

View file

@ -148,20 +148,24 @@ class VmwareServiceManager(PyVmomi):
try:
if self.desired_state in ['start', 'present']:
if not actual_service_state:
host_service_system.StartService(id=self.service_name)
if not self.module.check_mode:
host_service_system.StartService(id=self.service_name)
changed_state = True
elif self.desired_state in ['stop', 'absent']:
if actual_service_state:
host_service_system.StopService(id=self.service_name)
if not self.module.check_mode:
host_service_system.StopService(id=self.service_name)
changed_state = True
elif self.desired_state == 'restart':
host_service_system.RestartService(id=self.service_name)
if not self.module.check_mode:
host_service_system.RestartService(id=self.service_name)
changed_state = True
if self.desired_policy:
if actual_service_policy != self.desired_policy:
host_service_system.UpdateServicePolicy(id=self.service_name,
policy=self.desired_policy)
if not self.module.check_mode:
host_service_system.UpdateServicePolicy(id=self.service_name,
policy=self.desired_policy)
changed_state = True
host_service_state.append(changed_state)
@ -205,7 +209,8 @@ def main():
argument_spec=argument_spec,
required_one_of=[
['cluster_name', 'esxi_hostname'],
]
],
supports_check_mode=True
)
vmware_host_service = VmwareServiceManager(module)

View file

@ -83,7 +83,41 @@
state: absent
register: single_hosts_result
- name: ensure facts are gathered for all hosts
- name: ensure facts are gathered
assert:
that:
- single_hosts_result.changed == False
- name: Start ntpd service on all hosts in given cluster in check mode
vmware_host_service_manager:
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance.json.username }}"
password: "{{ vcsim_instance.json.password }}"
validate_certs: no
cluster_name: "{{ ccr1 }}"
service_name: ntpd
state: present
register: all_hosts_result_check_mode
check_mode: yes
- name: ensure facts are gathered for all hosts
assert:
that:
- all_hosts_result_check_mode.changed
- name: Stop ntpd service on a given host in check mode
vmware_host_service_manager:
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance.json.username }}"
password: "{{ vcsim_instance.json.password }}"
validate_certs: no
esxi_hostname: "{{ host1 }}"
service_name: ntpd
state: absent
register: single_hosts_result_check_mode
check_mode: yes
- name: ensure facts are gathered
assert:
that:
- single_hosts_result_check_mode.changed == False