使用 Ansible 和 firewalld 进行端口转发
Port forward with Ansible and firewalld
我正在试验 Ansible,想在 firewalld 中设置一个端口转发规则。
我试过以下方法:
- name: Port forward for 443
become: true
ansible.posix.firewalld:
port_forward:
- port: 443
proto: tcp
toport: 2443
state: enabled
这导致:
ERROR: Exception caught: queryForwardPort() got an unexpected keyword argument ''to_port''
如果我将其格式化为列表,它会说
Only one port forward supported at a time
如果我将其格式化为字典,我会得到:
argument port_forward is of type <class ''dict''> and we were unable to convert to list: <class ''dict''> cannot be converted to a list'
我正在使用带有 Ansible 2.10.8 的 Debian 11 VM。我安装了最新的 ansible.posix (1.3.0),因为包含的版本较旧 (1.1.1)。我可以在目标机器 (OEL 8) 上手动创建规则。
这是我使用 documentation.
知道如何让它工作吗?
提前致谢!
乍一看似乎有语法错误。第一条错误消息说
ERROR: Exception caught: queryForwardPort() got an unexpected keyword argument ''to_port''
to_port
,根据使用参数 rich_rule
的 firewalld
_module. Since your are on ansible.posix.collections
v1.3.0 and there is bug report open according Ansible Collections Ansible Posix Issue #247, were downgrading to v1.2.0 fix the issue, another approach might be according Ansible Issue #28349 的链接文档,它应该是 toport
。这也适用于 v1.1.1。
- name: Redirect port 443 to 8443
firewalld:
rich_rule: rule family={{ item }} forward-port port=443 protocol=tcp to-port=8443
zone: public
permanent: true
immediate: true
state: enabled
with_items:
- ipv4
- ipv6
要获取旧版本,您可以使用
ansible-galaxy collection install ansible.posix:1.2.0
语法错误在文件ansible.posix/plugins/modules/firewalld.py
中,似乎很简单,可以代表自己在本地修复它。
我正在试验 Ansible,想在 firewalld 中设置一个端口转发规则。
我试过以下方法:
- name: Port forward for 443
become: true
ansible.posix.firewalld:
port_forward:
- port: 443
proto: tcp
toport: 2443
state: enabled
这导致:
ERROR: Exception caught: queryForwardPort() got an unexpected keyword argument ''to_port''
如果我将其格式化为列表,它会说
Only one port forward supported at a time
如果我将其格式化为字典,我会得到:
argument port_forward is of type <class ''dict''> and we were unable to convert to list: <class ''dict''> cannot be converted to a list'
我正在使用带有 Ansible 2.10.8 的 Debian 11 VM。我安装了最新的 ansible.posix (1.3.0),因为包含的版本较旧 (1.1.1)。我可以在目标机器 (OEL 8) 上手动创建规则。
这是我使用 documentation.
知道如何让它工作吗?
提前致谢!
乍一看似乎有语法错误。第一条错误消息说
ERROR: Exception caught: queryForwardPort() got an unexpected keyword argument ''to_port''
to_port
,根据使用参数 rich_rule
的 firewalld
_module. Since your are on ansible.posix.collections
v1.3.0 and there is bug report open according Ansible Collections Ansible Posix Issue #247, were downgrading to v1.2.0 fix the issue, another approach might be according Ansible Issue #28349 的链接文档,它应该是 toport
。这也适用于 v1.1.1。
- name: Redirect port 443 to 8443
firewalld:
rich_rule: rule family={{ item }} forward-port port=443 protocol=tcp to-port=8443
zone: public
permanent: true
immediate: true
state: enabled
with_items:
- ipv4
- ipv6
要获取旧版本,您可以使用
ansible-galaxy collection install ansible.posix:1.2.0
语法错误在文件ansible.posix/plugins/modules/firewalld.py
中,似乎很简单,可以代表自己在本地修复它。