VMware: Add check mode support to module vmware_host_firewall_manager (#46266)

pull/46805/head
Christian Kotte 6 years ago committed by Abhijeet Kasurde
parent 0bc2e6795d
commit 2230f40041

@ -13,7 +13,7 @@ ANSIBLE_METADATA = {
'supported_by': 'community'
}
DOCUMENTATION = r'''
DOCUMENTATION = '''
---
module: vmware_host_firewall_manager
short_description: Manage firewall configurations about an ESXi host
@ -170,6 +170,7 @@ class VmwareFirewallManager(PyVmomi):
current_rule_state = self.firewall_facts[host.name][rule_name]['enabled']
if current_rule_state != rule_enabled:
try:
if not self.module.check_mode:
if rule_enabled:
firewall_system.EnableRuleset(id=rule_name)
else:
@ -206,7 +207,8 @@ def main():
argument_spec=argument_spec,
required_one_of=[
['cluster_name', 'esxi_hostname'],
]
],
supports_check_mode=True
)
vmware_firewall_manager = VmwareFirewallManager(module)

@ -84,7 +84,6 @@
- DC0_C0_H1
- DC0_C0_H2
- name: Disable vvold for {{ host1 }}
vmware_host_firewall_manager:
hostname: "{{ vcsim }}"
@ -113,3 +112,65 @@
- host_result.rule_set_state[item]['vvold']['previous_state'] == True
with_items:
- "{{ host1 }}"
- name: Enable vvold rule set on all hosts of {{ ccr1 }} in check mode
vmware_host_firewall_manager:
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance.json.username }}"
password: "{{ vcsim_instance.json.password }}"
validate_certs: no
cluster_name: "{{ ccr1 }}"
rules:
- name: vvold
enabled: True
register: all_hosts_result_check_mode
check_mode: yes
- debug: msg="{{ all_hosts_result_check_mode }}"
- name: ensure everything is changed for all hosts of {{ ccr1 }}
assert:
that:
- all_hosts_result_check_mode.changed
- all_hosts_result_check_mode.rule_set_state is defined
- name: ensure facts are gathered for all hosts of {{ ccr1 }}
assert:
that:
- all_hosts_result_check_mode.rule_set_state[item]['vvold']['current_state'] == True
- all_hosts_result_check_mode.rule_set_state[item]['vvold']['desired_state'] == True
- all_hosts_result_check_mode.rule_set_state[item]['vvold']['previous_state'] == False
with_items:
- DC0_C0_H0
- DC0_C0_H1
- DC0_C0_H2
- name: Disable vvold for {{ host1 }} in check mode
vmware_host_firewall_manager:
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance.json.username }}"
password: "{{ vcsim_instance.json.password }}"
validate_certs: no
esxi_hostname: "{{ host1 }}"
rules:
- name: vvold
enabled: False
register: host_result_check_mode
check_mode: yes
- debug: msg="{{ host_result_check_mode }}"
- name: ensure vvold is disabled for {{ host1 }}
assert:
that:
- host_result_check_mode.changed == False
- host_result_check_mode.rule_set_state is defined
- name: ensure facts are gathered for {{ host1 }}
assert:
that:
- host_result_check_mode.rule_set_state[item]['vvold']['current_state'] == False
- host_result_check_mode.rule_set_state[item]['vvold']['desired_state'] == False
- host_result_check_mode.rule_set_state[item]['vvold']['previous_state'] == False
with_items:
- "{{ host1 }}"

Loading…
Cancel
Save