I'm trying to use an Ansible playbook to save a current iptables rules.
Originally I would have used the command iptables-save > /etc/iptables/rules.v4
.
But when trying to use that command in Playbook I'm getting the following error:
"stderr_lines": [
"Unknown arguments found on commandline"
],
"cmd": [
"iptables-save",
">",
"/etc/iptables/rules.v4"
],
I tried to use the command
module and cmd
module and they both don't work, according to Ansible documentation the iptables module:
This module does not handle the saving and/or loading of rules, but rather only manipulates the current rules that are present in memory
My goal eventually is to save my firewall rules that will launch on every startup of a machine.
Have a temporary solution using a bash script that does that task if anyone have another solution any help will be much appreciated .
(Converting my comment as an answer as requested by OP)
You are using the command module which does not support redirections and pipes.
You should use shell
in this situation.
I am not 100% sure you can do exactly what you want with the dedicated iptable
modules. Some people managed that through a custom module.