ansible命令:模块返回错误

时间:2014-06-11 08:15:00

标签: rhel ansible

尝试使用ansible进行iptables-save

name: Save Netfilter Rules

action: command  iptables-save > /etc/sysconfig/iptables

但是这会给出错误

failed: [10.110.211.17] => {"changed": true, "cmd": ["iptables-save", ">", "/etc/sysconfig/iptables"], "delta": "0:00:00.009345", "end": "2014-06-09 16:55:18.306375", "rc": 1, "start": "2014-06-09 16:55:18.297030"}

stderr: Unknown arguments found on commandline

但是在ssh上这很好用:

ssh root@host "iptables-save > /etc/sysconfig/iptables" 

工作正常但不通过Ansible命令:module

我该如何开展这项工作

1 个答案:

答案 0 :(得分:10)

您应该使用shell模块进行重定向,即

...
name: Save Netfilter Rules
shell:  iptables-save > /etc/sysconfig/iptables

ansible docs