Skip to content

Commit

Permalink
VMware: Add check mode support to module vmware_host_service_manager (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
ckotte authored and Akasurde committed Oct 8, 2018
1 parent 77127d6 commit c4cfeb1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
17 changes: 11 additions & 6 deletions lib/ansible/modules/cloud/vmware/vmware_host_service_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,24 @@ def service_ctrl(self):
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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c4cfeb1

Please sign in to comment.