2017-03-24 04:01:26 +01:00
|
|
|
- name: Remove potentially leftover firewall rule
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
state: absent
|
2017-08-29 22:18:03 +02:00
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
2017-03-24 04:01:26 +01:00
|
|
|
|
|
|
|
- name: Add firewall rule
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
register: add_firewall_rule
|
|
|
|
|
|
|
|
- name: Check that creating new firewall rule succeeds with a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule.changed == true
|
|
|
|
|
|
|
|
- name: Add same firewall rule (again)
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
register: add_firewall_rule_again
|
|
|
|
|
|
|
|
- name: Check that creating same firewall rule succeeds without a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_again.changed == false
|
|
|
|
|
|
|
|
- name: Remove firewall rule
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: absent
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
register: remove_firewall_rule
|
|
|
|
|
|
|
|
- name: Check that removing existing firewall rule succeeds with a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- remove_firewall_rule.changed == true
|
|
|
|
|
|
|
|
- name: Remove absent firewall rule
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: absent
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
register: remove_absent_firewall_rule
|
|
|
|
|
|
|
|
- name: Check that removing non existing firewall rule succeeds without a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- remove_absent_firewall_rule.changed == false
|
|
|
|
|
|
|
|
- name: Add firewall rule
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
|
2017-08-29 22:18:03 +02:00
|
|
|
- name: Change firewall rule
|
2017-03-24 04:01:26 +01:00
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: block
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-08-29 22:18:03 +02:00
|
|
|
register: change_firewall_rule
|
2017-03-24 04:01:26 +01:00
|
|
|
|
2017-08-29 22:18:03 +02:00
|
|
|
- name: Check that changing firewall rule succeeds
|
2017-03-24 04:01:26 +01:00
|
|
|
assert:
|
|
|
|
that:
|
2017-08-29 22:18:03 +02:00
|
|
|
- change_firewall_rule.changed == true
|
2017-03-24 04:01:26 +01:00
|
|
|
|
2019-04-10 01:27:31 +02:00
|
|
|
- name: Disable firewall rule
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: no
|
|
|
|
|
|
|
|
- name: Get the actual values from the changed firewall rule
|
|
|
|
win_shell: '(New-Object -ComObject HNetCfg.FwPolicy2).Rules | Where-Object { $_.Name -eq "http" } | Foreach-Object { $_.LocalPorts; $_.Enabled; $_.Action; $_.Direction; $_.Protocol }'
|
|
|
|
register: firewall_rule_actual
|
|
|
|
|
|
|
|
- name: Ensure that disabling the rule did not change the previous values
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "firewall_rule_actual.stdout_lines[0] == '80'" # LocalPorts = 80
|
|
|
|
- "firewall_rule_actual.stdout_lines[1] == 'False'" # Enabled = False
|
|
|
|
- "firewall_rule_actual.stdout_lines[2] == '0'" # Action = block
|
|
|
|
- "firewall_rule_actual.stdout_lines[3] == '1'" # Direction = in
|
|
|
|
- "firewall_rule_actual.stdout_lines[4] == '6'" # Protocol = tcp
|
|
|
|
|
2017-03-24 04:01:26 +01:00
|
|
|
- name: Add firewall rule when remoteip is range
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
remoteip: 192.168.0.1-192.168.0.5
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
|
|
|
|
- name: Add same firewall rule when remoteip is range (again)
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
remoteip: 192.168.0.1-192.168.0.5
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
register: add_firewall_rule_with_range_remoteip_again
|
|
|
|
|
|
|
|
- name: Check that creating same firewall rule when remoteip is range succeeds without a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_range_remoteip_again.changed == false
|
|
|
|
|
|
|
|
- name: Add firewall rule when remoteip in CIDR notation
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
remoteip: 192.168.0.0/24
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
|
|
|
|
- name: Add same firewall rule when remoteip in CIDR notation (again)
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
remoteip: 192.168.0.0/24
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
register: add_firewall_rule_with_cidr_remoteip_again
|
|
|
|
|
|
|
|
- name: Check that creating same firewall rule succeeds without a change when remoteip in CIDR notation
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_cidr_remoteip_again.changed == false
|
|
|
|
|
|
|
|
- name: Add firewall rule when remoteip contains a netmask
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
2017-08-29 22:18:03 +02:00
|
|
|
remoteip: 192.168.1.0/255.255.255.0
|
2017-03-24 04:01:26 +01:00
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
|
|
|
|
- name: Add same firewall rule when remoteip contains a netmask (again)
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
2017-08-29 22:18:03 +02:00
|
|
|
remoteip: 192.168.1.0/255.255.255.0
|
2017-03-24 04:01:26 +01:00
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
register: add_firewall_rule_remoteip_contains_netmask_again
|
|
|
|
|
|
|
|
- name: Check that creating same firewall rule succeeds without a change when remoteip contains a netmask
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_remoteip_contains_netmask_again.changed == false
|
|
|
|
|
|
|
|
- name: Add firewall rule when remoteip is IPv4
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
remoteip: 192.168.0.1
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
|
|
|
|
- name: Add same firewall rule when remoteip is IPv4 (again)
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
2017-05-31 01:10:34 +02:00
|
|
|
enabled: yes
|
2017-03-24 04:01:26 +01:00
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
remoteip: 192.168.0.1
|
|
|
|
action: allow
|
2017-05-31 01:10:34 +02:00
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
2017-03-24 04:01:26 +01:00
|
|
|
register: add_firewall_rule_with_ipv4_remoteip_again
|
|
|
|
|
|
|
|
- name: Check that creating same firewall rule when remoteip is IPv4 succeeds without a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_ipv4_remoteip_again.changed == false
|
2017-08-29 22:18:03 +02:00
|
|
|
|
|
|
|
- name: Add firewall rule when remoteip contains a netmask
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
remoteip: 192.168.2.0/255.255.255.0
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
|
|
|
|
- name: Add same firewall rule when remoteip in CIDR notation
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
remoteip: 192.168.2.0/24
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
register: add_same_firewall_rule_with_cidr_remoteip
|
|
|
|
|
|
|
|
- name: Check that creating same firewall rule succeeds without a change when remoteip contains a netmask or CIDR
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_same_firewall_rule_with_cidr_remoteip.changed == false
|
|
|
|
|
|
|
|
- name: Add firewall rule with multiple ports
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: '80,81'
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
register: add_firewall_rule_with_multiple_ports
|
|
|
|
|
|
|
|
- name: Check that creating firewall rule with multiple ports succeeds with a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_multiple_ports.changed == true
|
|
|
|
|
2017-10-10 08:23:08 +02:00
|
|
|
- name: Add firewall rule with interface types in string format
|
2017-08-29 22:18:03 +02:00
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
interfacetypes: 'ras,lan,wireless'
|
2017-10-10 08:23:08 +02:00
|
|
|
register: add_firewall_rule_with_string_interface_types
|
2017-08-29 22:18:03 +02:00
|
|
|
|
2017-10-10 08:23:08 +02:00
|
|
|
- name: Check that creating firewall rule with interface types in string format succeeds with a change
|
2017-08-29 22:18:03 +02:00
|
|
|
assert:
|
|
|
|
that:
|
2017-10-10 08:23:08 +02:00
|
|
|
- add_firewall_rule_with_string_interface_types.changed == true
|
|
|
|
|
|
|
|
- name: Add firewall rule with interface types in list format
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
interfacetypes: [ras, lan]
|
|
|
|
register: add_firewall_rule_with_list_interface_types
|
|
|
|
|
|
|
|
- name: Check that creating firewall rule with interface types in list format succeeds with a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_list_interface_types.changed == true
|
2017-08-29 22:18:03 +02:00
|
|
|
|
|
|
|
- name: Add firewall rule with interface type 'any'
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
interfacetypes: any
|
|
|
|
register: add_firewall_rule_with_interface_type_any
|
|
|
|
|
|
|
|
- name: Check that creating firewall rule with interface type 'any' succeeds with a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_interface_type_any.changed == true
|
|
|
|
|
|
|
|
- name: Add firewall rule with edge traversal option 'deferapp'
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
edge: deferapp
|
|
|
|
register: add_firewall_rule_with_edge_traversal
|
|
|
|
|
|
|
|
# Setup action creates ansible_distribution_version variable
|
|
|
|
- action: setup
|
|
|
|
|
|
|
|
- name: Check that creating firewall rule with enge traversal option 'deferapp' succeeds with a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_edge_traversal.changed == true
|
|
|
|
# Works on windows >= Windows 7/Windows Server 2008 R2
|
2017-11-27 23:58:08 +01:00
|
|
|
when: ansible_distribution_version is version('6.1', '>=')
|
2017-08-29 22:18:03 +02:00
|
|
|
|
|
|
|
- name: Add firewall rule with 'authenticate' secure flag
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
security: authenticate
|
|
|
|
register: add_firewall_rule_with_secure_flags
|
|
|
|
|
|
|
|
- name: Check that creating firewall rule with secure flag 'authenticate' succeeds with a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_secure_flags.changed == true
|
|
|
|
# Works on windows >= Windows 8/Windows Server 2012
|
2017-11-27 23:58:08 +01:00
|
|
|
when: ansible_distribution_version is version('6.2', '>=')
|
2017-10-10 08:23:08 +02:00
|
|
|
|
|
|
|
- name: Add firewall rule with profiles in string format
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
profiles: 'domain,public'
|
|
|
|
register: add_firewall_rule_with_string_profiles
|
|
|
|
|
|
|
|
- name: Check that creating firewall rule with profiles in string format succeeds with a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_string_profiles.changed == true
|
|
|
|
|
2018-01-03 05:25:46 +01:00
|
|
|
- name: Set firewall rule profile back to 'all'
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
profiles: [Domain, Public, Private]
|
|
|
|
register: add_firewall_rule_with_string_profiles
|
|
|
|
|
|
|
|
- name: Check that setting firewall rule profile back to 'all' succeeds with a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_string_profiles.changed == true
|
|
|
|
|
2017-10-10 08:23:08 +02:00
|
|
|
- name: Add firewall rule with profiles in list format
|
|
|
|
win_firewall_rule:
|
|
|
|
name: http
|
|
|
|
enabled: yes
|
|
|
|
state: present
|
|
|
|
localport: 80
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
profiles: [Domain, Private]
|
|
|
|
register: add_firewall_rule_with_list_profiles
|
|
|
|
|
|
|
|
- name: Check that creating firewall rule with profiles in list format succeeds with a change
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- add_firewall_rule_with_list_profiles.changed == true
|