Ansible ufw模块错误:找不到匹配的配置文件';xxxxx和x27;
我正在通过Ansible建立UFW规则。我可以安装它,启动它,拒绝一切。然后,我尝试允许来自http、https和ssh的连接。所有为这些项目添加允许的尝试都会遇到如下错误:Ansible ufw模块错误:找不到匹配的配置文件';xxxxx和x27;,ansible,ansible-playbook,ufw,Ansible,Ansible Playbook,Ufw,我正在通过Ansible建立UFW规则。我可以安装它,启动它,拒绝一切。然后,我尝试允许来自http、https和ssh的连接。所有为这些项目添加允许的尝试都会遇到如下错误: failed: [lempy1] (item={u'service': u'http'}) => {"failed": true, "item": {"service": "http"}, "msg": "ERROR: Could not find a profile matching 'http'\n"} fail
failed: [lempy1] (item={u'service': u'http'}) => {"failed": true, "item": {"service": "http"}, "msg": "ERROR: Could not find a profile matching 'http'\n"}
failed: [lempy1] (item={u'service': u'https'}) => {"failed": true, "item": {"service": "https"}, "msg": "ERROR: Could not find a profile matching 'https'\n"}
failed: [lempy1] (item={u'service': u'ssh'}) => {"failed": true, "item": {"service": "ssh"}, "msg": "ERROR: Could not find a profile matching 'ssh'\n"}
整个角色如下所示:
[CUPS]
title=Common UNIX Printing System server
description=CUPS is a printing system with support for IPP, samba, lpd, and other protocols.
ports=631
tasks/main.yml
知道我为什么不能允许这些服务吗?当ssh'ing进入服务器并运行sudo ufw allow http
等时,我能够正确添加服务。如中所述,name(或app)参数使用在/etc/ufw/applications.d
中注册的应用程序,这些应用程序具有INI格式,如下所示:
[CUPS]
title=Common UNIX Printing System server
description=CUPS is a printing system with support for IPP, samba, lpd, and other protocols.
ports=631
通常,您可以使用ufw-allow-application-profile
来允许在/etc/ufw/applications.d
或/etc/services
中定义的应用程序为/etc/ufw/applications.d
中不一定定义的内容打开iptable
不幸的是,Ansible以以下格式生成ufw命令:
/usr/sbin/ufw allow from any to any app 'application-profile'
它只使用/etc/ufw/applications.d
列表,不会读取/etc/services
在您的情况下,您可以简单地指定这些众所周知的端口,可能会使用命名变量来进一步解释您的Ansible代码:
- name: Allow webservery things
ufw:
rule: allow
port: '{{ item }}'
with_items:
- '{{ http_port }}'
- '{{ https_port }}'
- '{{ ssh_port }}'
tags:
- security
然后在某个地方定义变量(例如您的角色默认值):
顺便说一句,您可能会注意到,我用一个键将您的字典列表简化为一个更简单的直接列表,这会稍微整理一下您的任务
或者,您可以使用Ansible轻松地模板化应用程序配置文件。它是否与使用单引号传输的规则名称相关?我知道YAML强迫你引用{{和}},但是你可以尝试用
“{{item.service}}”替换”{{{item.service}}}{/code>,并检查结果。因此我仍然得到了无法找到与“80”匹配的配置文件的结果。对于我尝试分配的所有其他端口也是如此。错误看起来像:{“failed”:true,“item”:80,“msg”:“Error:找不到与'80'匹配的配置文件\n”}。有什么想法吗?我的任务现在看起来和你在这里布置的一模一样。我想知道模板是否是最好的选择。抱歉,这应该是端口而不是名称。当我把你的代码复制到我的答案中时,忘了编辑它了。我把那部分弄得乱七八糟,再次感谢你!
http_port: 80
https_port: 443
ssh_port: 22