community.proxmox.proxmox_firewall module – Manage firewall rules in Proxmox
Note
This module is part of the community.proxmox collection (version 1.4.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.proxmox.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.proxmox.proxmox_firewall.
New in community.proxmox 1.4.0
Synopsis
create/update/delete FW rules at cluster/group/vnet/node/vm level
Create/delete firewall security groups
Create/delete aliases
Requirements
The below requirements are needed on the host that executes this module.
proxmoxer >= 2.0
requests
Parameters
Parameter |
Comments |
|---|---|
List of aliases. Alias can only be created/updated/deleted at cluster or VM level. |
|
CIDR for alias. Only needed when |
|
Comment for alias. |
|
Alias name. |
|
Specify the target host of the Proxmox VE cluster. Uses the |
|
Specify the password to authenticate with. Uses the |
|
Specify the target port of the Proxmox VE cluster. Uses the |
|
Specify the token ID. Uses the |
|
Specify the token secret. Uses the |
|
Specify the user to authenticate with. Uses the |
|
Comment for security group. Only needed when creating group. |
|
Name of the group to which the rule belongs. Only needed when |
|
Whether security group should be created or deleted. Choices:
|
|
List of IP set definitions to create, update, or remove. Each IP set is a named collection of CIDRs (with optional negation and comments). |
|
List of CIDR entries in the IP set. |
|
CIDR notation for the entry. |
|
Optional comment for this CIDR entry. |
|
When true, this CIDR acts as a negative match (exclusion) within the set. Choices:
|
|
Optional comment for the IP set. |
|
Unique name of the IP set. |
|
Level at which the firewall rule applies. Choices:
|
|
Name of the node. Only needed when |
|
Position of the rule in the list. Only needed if |
|
List of individual rules to be applied. |
|
Rule action (‘ACCEPT’, ‘DROP’, ‘REJECT’) or security group name. |
|
Optional comment for the specific rule. |
|
Restrict packet destination address. This can refer to a single IP address, an IP set (‘+ipsetname’) or an IP alias definition. You can also specify an address range like ‘20.34.101.207-201.3.9.99’, or a list of IP addresses and networks (entries are separated by comma). Please do not mix IPv4 and IPv6 addresses inside such lists. |
|
Prevent changes if current configuration file has a different digest. This can be used to prevent concurrent modifications. If not provided we will calculate at runtime. |
|
Restrict TCP/UDP destination port. You can use service names or simple numbers (0-65535), as defined in ‘/etc/services’. Port ranges can be specified with ‘\d+:\d+’, for example ‘80:85’, and you can use comma separated list to match several ports or ranges. |
|
Enable or disable the rule. Choices:
|
|
Specify icmp-type. Only valid if proto equals ‘icmp’ or ‘icmpv6’/’ipv6-icmp’. |
|
Network interface name. You have to use network configuration key names for VMs and containers (‘net\d+’). Host related rules can use arbitrary strings. |
|
Logging level for the rule. Choices:
|
|
Use predefined standard macro. |
|
Position of the rule in the list. |
|
IP protocol. You can use protocol names (‘tcp’/’udp’) or simple numbers, as defined in ‘/etc/protocols’. |
|
Restrict packet source address. This can refer to a single IP address, an IP set (‘+ipsetname’) or an IP alias definition. You can also specify an address range like ‘20.34.101.207-201.3.9.99’, or a list of IP addresses and networks (entries are separated by comma). Please do not mix IPv4 and IPv6 addresses inside such lists. |
|
Restrict TCP/UDP source port. You can use service names or simple numbers (0-65535), as defined in ‘/etc/services’. Port ranges can be specified with ‘\d+:\d+’, for example ‘80:85’, and you can use comma separated list to match several ports or ranges. |
|
Rule type. Choices:
|
|
Create/update/delete firewall rules or security group. Choices:
|
|
If Choices:
|
|
If This should only be used on personally controlled sites using self-signed certificates. Uses the Choices:
|
|
ID of the VM to which the rule applies. Only needed when |
|
Name of the virtual network for the rule. Only needed when |
Attributes
Attribute |
Support |
Description |
|---|---|---|
Action group: community.proxmox.proxmox |
Use |
|
Support: none |
Can run in |
|
Support: none |
Will return details on what has changed (or possibly needs changing in |
Examples
- name: Create firewall rules at cluster level
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
level: cluster
state: present
rules:
- type: out
action: ACCEPT
source: 1.1.1.1
log: nolog
pos: 9
enable: true
- type: out
action: ACCEPT
source: 1.0.0.1
pos: 10
enable: true
- name: Update Cluster level firewall rules
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
level: cluster
state: present
update: true
rules:
- type: out
action: ACCEPT
source: 8.8.8.8
log: nolog
pos: 9
enable: false
- type: out
action: ACCEPT
source: 8.8.4.4
pos: 10
enable: false
- name: Delete cluster level firewall rule at pos 10
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
level: cluster
state: absent
pos: 10
- name: Create security group
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
group_conf: true
state: present
group: test
- name: Delete security group
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
group_conf: true
state: absent
group: test
- name: Create FW aliases
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
state: present
aliases:
- name: test1
cidr: '10.10.1.0/24'
- name: test2
cidr: '10.10.2.0/24'
- name: Update FW aliases
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
state: present
update: true
aliases:
- name: test1
cidr: '10.10.1.0/28'
- name: test2
cidr: '10.10.2.0/28'
- name: Delete FW aliases
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
state: absent
aliases:
- name: test1
- name: test2
- name: Create IP SET
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
ip_sets:
- name: hypervisors
comment: PVE hosts
cidrs:
- cidr: 192.168.1.10
nomatch: false
comment: Proxmox pve-01
- cidr: 192.168.1.11
nomatch: true
comment: Proxmox pve-02
- name: test
comment: PVE hosts
cidrs:
- cidr: 10.10.1.0
comment: Proxmox pve-01
- name: Delete IP SETs
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
state: absent
ip_sets:
- name: hypervisors
- name: Delete specific CIDR from IP SET
community.proxmox.proxmox_firewall:
api_user: "{{ pc.proxmox.api_user }}"
api_token_id: "{{ pc.proxmox.api_token_id }}"
api_token_secret: "{{ vault.proxmox.api_token_secret }}"
api_host: "{{ pc.proxmox.api_host }}"
validate_certs: false
state: absent
ip_sets:
- name: test
cidrs:
- cidr: 10.10.1.0
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
|---|---|
group name which was created/deleted Returned: on success Sample: |