---
- name: Install iptables-persistent
  apt: 
    name: iptables-persistent
    update_cache: yes
    state: present

- name: Check if netfilter-persistent is present
  shell: which netfilter-persistent
  register: is_netfilter
  when: v4_script|changed
  changed_when: false
  ignore_errors: yes
  check_mode: no

- name: Save rules (netfilter-persistent)
  command: netfilter-persistent save
  when: not ansible_check_mode and v4_script|changed and is_netfilter.rc == 0

- name: Save rules (iptables-persistent)
  command: /etc/init.d/iptables-persistent save
  when: not ansible_check_mode and v4_script|changed and is_netfilter.rc == 1
