ansible iptables `state=absent` が動かない。
ansibleのモジュールiptablesで'state=present'が機能しない。
ansibleでiptablesをメンテナンスしようとおもい、以下のモジュールを利用したが、どうにも state=absent
が動かない。
iptablesモジュールのソースを追ってみたところ、以下のようにchangedを判定しているのだが、
# /usr/lib/python2.6/site-packages/ansible/modules/extras/system/iptables.py def check_present(iptables_path, module, params): cmd = push_arguments(iptables_path, '-C', params) rc, _, __ = module.run_command(cmd, check_rc=False) return (rc == 0)
この -C(--check)
はどうやら最近のiptablesしか持っていないようで、これがうまく機能しないため、changedは常にfalseになるようだ。
$ cat /etc/redhat-release CentOS release 6.4 (Final) $ sudo iptables --check INPUT -p tcp -s 0.0.0.0/0 -d 0.0.0.0/0 -j REJECT --destination-port 25 iptables v1.4.7: unknown option `--check' Try `iptables -h' or 'iptables --help' for more information.
ソースを追わないと気づけないのが問題だと思う。↓
return (rc == 0)