Invalid interface clause error with ufw module and log param

I have some tasks that use the ufw module to add firewall rules, which up until now have been working fine. Today however, I added the ‘log’ parameter to the ufw task and I got the following error: “ERROR: Invalid interface clause”.

My task definition is below:

  • name: apply rules using ‘firewall’ variable defined in inventory vars
    ufw:
    port: “{{ item.0.port|default(omit) }}”
    proto: “{{ item.0.proto|default(omit) }}”
    src: “{{ item.1 }}”
    rule: “{{ item.0.rule }}”
    direction: “{{ item.0.direction|default(omit) }}”
    log: “{{ item.0.log|default(‘no’) }}”
    state: enabled
    with_subelements:
  • “{{ firewall.rules }}”
  • src

The troublesome firewall variable that’s failing for the task above is:

firewall:
rules:
ssh:
port: 22
proto: tcp
src: “{{ ips.ssh }}”
rule: allow
direction: in
log: ‘yes’

If I remove log: “{{ item.0.log|default(‘no’) }}” from the ufw task it works fine.

Thanks,
Guy

I tried changing this task to not use a loop and instead just made it a standard task definition, as below:

  • name: apply ssh rule
    ufw:
    port: 22
    proto: ‘tcp’
    src: ‘192.168.0.0/24’
    rule: allow
    direction: in
    log: ‘yes’
    interface: eth0
    state: enabled

I tried it with and without the interface parameter but I still get the same error, “Invalid interface clause”. The only interface in this machine is eth0 so the interface name is correct.

Does anyone have a solution for this?

Guy