community / community.general / 1.3.14 / module / hetzner_firewall Manage Hetzner's dedicated server firewall | "added in version" 0.2.0 of community.general" Authors: Felix Fontein (@felixfontein)community.general.hetzner_firewall (1.3.14) — module
Install with ansible-galaxy collection install community.general:==1.3.14
collections: - name: community.general version: 1.3.14
Manage Hetzner's dedicated server firewall.
Note that idempotency check for TCP flags simply compares strings and doesn't try to interpret the rules. This might change in the future.
- name: Configure firewall for server with main IP 1.2.3.4 community.general.hetzner_firewall: hetzner_user: foo hetzner_password: bar server_ip: 1.2.3.4 state: present whitelist_hos: yes rules: input: - name: Allow everything to ports 20-23 from 4.3.2.1/24 ip_version: ipv4 src_ip: 4.3.2.1/24 dst_port: '20-23' action: accept - name: Allow everything to port 443 ip_version: ipv4 dst_port: '443' action: accept - name: Drop everything else ip_version: ipv4 action: discard register: result
- ansible.builtin.debug: msg: "{{ result }}"
port: choices: - main - kvm default: main description: - Switch port of firewall. type: str rules: description: - Firewall rules. suboptions: input: description: - Input firewall rules. elements: dict suboptions: action: choices: - accept - discard description: - Action if rule matches. required: true type: str dst_ip: description: - Destination IP address or subnet address. - CIDR notation. type: str dst_port: description: - Destination port or port range. type: str ip_version: choices: - ipv4 - ipv6 description: - Internet protocol version. - Note that currently, only IPv4 is supported by Hetzner. required: true type: str name: description: - Name of the firewall rule. type: str protocol: description: - Protocol above IP layer type: str src_ip: description: - Source IP address or subnet address. - CIDR notation. type: str src_port: description: - Source port or port range. type: str tcp_flags: description: - TCP flags or logical combination of flags. - Flags supported by Hetzner are C(syn), C(fin), C(rst), C(psh) and C(urg). - They can be combined with C(|) (logical or) and C(&) (logical and). - See L(the documentation,https://wiki.hetzner.de/index.php/Robot_Firewall/en#Parameter) for more information. type: str type: list type: dict state: choices: - present - absent default: present description: - Status of the firewall. - Firewall is active if state is C(present), and disabled if state is C(absent). type: str timeout: default: 180 description: - Timeout (in seconds) for waiting for firewall to be configured. type: int server_ip: description: The server's main IP address. required: true type: str wait_delay: default: 10 description: - Delay to wait (in seconds) before checking again whether the firewall has been configured. type: int hetzner_user: description: The username for the Robot webservice user. required: true type: str whitelist_hos: description: - Whether Hetzner services have access. type: bool update_timeout: default: 30 description: - Timeout to use when configuring the firewall. - Note that the API call returns before the firewall has been successfully set up. type: int hetzner_password: description: The password for the Robot webservice user. required: true type: str wait_for_configured: default: true description: - Whether to wait until the firewall has been successfully configured before determining what to do, and before returning from the module. - The API returns status C(in progress) when the firewall is currently being configured. If this happens, the module will try again until the status changes to C(active) or C(disabled). - Please note that there is a request limit. If you have to do multiple updates, it can be better to disable waiting, and regularly use M(community.general.hetzner_firewall_info) to query status. type: bool
firewall: contains: port: description: - Switch port of firewall. - C(main) or C(kvm). sample: main type: str rules: contains: input: contains: action: description: - Action if rule matches. - C(accept) or C(discard). sample: accept type: str dst_ip: description: - Destination IP address or subnet address. - CIDR notation. sample: 1.2.3.4/32 type: str dst_port: description: - Destination port or port range. sample: '443' type: str ip_version: description: - Internet protocol version. sample: ipv4 type: str name: description: - Name of the firewall rule. sample: Allow HTTP access to server type: str protocol: description: - Protocol above IP layer sample: tcp type: str src_ip: description: - Source IP address or subnet address. - CIDR notation. sample: null type: str src_port: description: - Source port or port range. sample: null type: str tcp_flags: description: - TCP flags or logical combination of flags. sample: null type: str description: - Input firewall rules. elements: dict type: list description: - Firewall rules. type: dict server_ip: description: - Server's main IP address. sample: 1.2.3.4 type: str server_number: description: - Hetzner's internal server number. sample: 12345 type: int status: description: - Status of the firewall. - C(active) or C(disabled). - Will be C(in process) if the firewall is currently updated, and I(wait_for_configured) is set to C(no) or I(timeout) to a too small value. sample: active type: str whitelist_hos: description: - Whether Hetzner services have access. sample: true type: bool description: - The firewall configuration. returned: success type: dict