Skip to content

Instantly share code, notes, and snippets.

@amiorin
Last active August 29, 2015 14:12
Show Gist options
  • Save amiorin/c35549f1ff159580001c to your computer and use it in GitHub Desktop.
Save amiorin/c35549f1ff159580001c to your computer and use it in GitHub Desktop.
Ansible idempotent iptables add rule
---
- name: Check forward udp port 53
command: iptables -t nat -C PREROUTING -i {{ eth }} -p udp --dport 53 -j REDIRECT --to-port 8600
register: result
failed_when: False
changed_when: False
when: server
tags: iptables
- name: Forward udp port 53
command: iptables -t nat -A PREROUTING -i {{ eth }} -p udp --dport 53 -j REDIRECT --to-port 8600
when: server and result|failed
tags: iptables
- name: Check forward udp port 53 localhost
command: iptables -t nat -C OUTPUT -o lo -p udp --dport 53 -j REDIRECT --to-ports 8600
register: result
failed_when: False
changed_when: False
when: server
tags: iptables
- name: Forward udp port 53 localhost
command: iptables -t nat -A OUTPUT -o lo -p udp --dport 53 -j REDIRECT --to-ports 8600
when: server and result|failed
tags: iptables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment