2015-03-16 10:34:07 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# (c) 2014, Timothy Vandenbrande <timothy.vandenbrande@gmail.com>
|
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
2016-12-06 10:35:25 +00:00
|
|
|
|
2017-01-19 01:57:33 +00:00
|
|
|
DOCUMENTATION = r'''
|
2015-03-16 10:34:07 +00:00
|
|
|
---
|
2015-10-06 09:47:27 +00:00
|
|
|
module: win_firewall_rule
|
2015-07-02 08:00:33 +00:00
|
|
|
version_added: "2.0"
|
2015-03-16 10:34:07 +00:00
|
|
|
author: Timothy Vandenbrande
|
|
|
|
short_description: Windows firewall automation
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- Allows you to create/remove/update firewall rules
|
2015-10-06 13:03:27 +00:00
|
|
|
options:
|
2017-05-30 23:10:34 +00:00
|
|
|
enabled:
|
2015-10-06 13:03:27 +00:00
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- Is this firewall rule enabled or disabled
|
|
|
|
default: 'yes'
|
|
|
|
choices: [ 'no', 'yes' ]
|
|
|
|
aliases: [ 'enable' ]
|
2015-03-16 10:34:07 +00:00
|
|
|
state:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- Should this rule be added or removed
|
2015-03-16 10:34:07 +00:00
|
|
|
default: "present"
|
|
|
|
choices: ['present', 'absent']
|
|
|
|
name:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- The rules name
|
2015-03-16 10:34:07 +00:00
|
|
|
required: true
|
|
|
|
direction:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- Is this rule for inbound or outbound traffic
|
2015-03-16 10:34:07 +00:00
|
|
|
required: true
|
2016-06-20 21:35:27 +00:00
|
|
|
choices: ['in', 'out']
|
2015-03-16 10:34:07 +00:00
|
|
|
action:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- What to do with the items this rule is for
|
2015-03-16 10:34:07 +00:00
|
|
|
required: true
|
2016-06-20 21:35:27 +00:00
|
|
|
choices: ['allow', 'block', 'bypass']
|
2015-03-16 10:34:07 +00:00
|
|
|
description:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- Description for the firewall rule
|
2015-03-16 10:34:07 +00:00
|
|
|
localip:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- The local ip address this rule applies to
|
2016-06-20 21:35:27 +00:00
|
|
|
default: 'any'
|
2015-03-16 10:34:07 +00:00
|
|
|
remoteip:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- The remote ip address/range this rule applies to
|
2016-06-20 21:35:27 +00:00
|
|
|
default: 'any'
|
2015-03-16 10:34:07 +00:00
|
|
|
localport:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- The local port this rule applies to
|
2015-03-16 10:34:07 +00:00
|
|
|
remoteport:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- The remote port this rule applies to
|
2015-03-16 10:34:07 +00:00
|
|
|
program:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- The program this rule applies to
|
2015-03-16 10:34:07 +00:00
|
|
|
service:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- The service this rule applies to
|
2015-03-16 10:34:07 +00:00
|
|
|
protocol:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- The protocol this rule applies to
|
2016-06-20 21:35:27 +00:00
|
|
|
default: 'any'
|
2017-05-30 23:10:34 +00:00
|
|
|
profiles:
|
2015-10-05 20:53:11 +00:00
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- The profile this rule applies to
|
|
|
|
default: 'domain,private,public'
|
|
|
|
aliases: [ 'profile' ]
|
2015-03-16 10:34:07 +00:00
|
|
|
force:
|
|
|
|
description:
|
2017-05-30 23:10:34 +00:00
|
|
|
- Replace any existing rule by removing it first.
|
|
|
|
default: 'no'
|
|
|
|
choices: [ 'no', 'yes' ]
|
|
|
|
notes:
|
|
|
|
- The implementation uses C(netsh advfirewall) underneath, a pure-Powershell
|
|
|
|
reimplementation would be more powerful.
|
|
|
|
- Modifying existing firewall rules is not possible, the module does allow
|
|
|
|
replacing complete rules based on name, but that works by removing the
|
|
|
|
existing rule completely, and recreating it with provided information
|
|
|
|
(when using C(force)).
|
2015-03-16 10:34:07 +00:00
|
|
|
'''
|
|
|
|
|
2017-01-19 01:57:33 +00:00
|
|
|
EXAMPLES = r'''
|
2017-05-30 23:10:34 +00:00
|
|
|
- name: Firewall rule to allow SMTP on TCP port 25
|
|
|
|
win_firewall_rule:
|
|
|
|
name: SMTP
|
|
|
|
localport: 25
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
state: present
|
|
|
|
enabled: yes
|
2015-03-16 10:34:07 +00:00
|
|
|
|
2017-05-30 23:10:34 +00:00
|
|
|
- name: Firewall rule to allow RDP on TCP port 3389
|
|
|
|
win_firewall_rule:
|
|
|
|
name: Remote Desktop
|
|
|
|
localport: 3389
|
|
|
|
action: allow
|
|
|
|
direction: in
|
|
|
|
protocol: tcp
|
|
|
|
profiles: private
|
|
|
|
state: present
|
|
|
|
enabled: yes
|
2015-06-30 06:39:19 +00:00
|
|
|
'''
|