2

How can I use Ansible's ufw module to set DEFAULT_FORWARD_POLICY="ACCEPT" as recommended when setting up Docker?

I know I can do it with lineinfile, but it would be nice to use the ufw module if possible, and with my limited sysadmin experience it's not clear to me how to do this from the ufw module documentation (and I'd rather not botch firewall rules if possible).

2

2 Answers 2

4

This post seems to be quite old but for somebody looking for this problem the following task worked for me

- name: 'Allow docker DEFAULT_FORWARD_POLICY=ACCEPT'
  ufw: direction=routed default=allow route=yes

Hope that helps someone

2

until a solution using the ufw module is posted, here is my current lineinfile solution for anyone that stumbles upon this question with a similar issue:

---
- name: docker
  hosts: docker
  become: true
  become_user: root

  handlers:
  - name: reload ufw
    command: ufw reload

  tasks:
  - name: set UFW default forward policy to ACCEPT
    lineinfile:
      dest: /etc/default/ufw
      line: DEFAULT_FORWARD_POLICY="ACCEPT"
      regexp: "^DEFAULT_FORWARD_POLICY\\="
    notify: reload ufw

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .