Ansible: Use inventory_hostname variable in lineinfile module
The issue seems resolved, If I escape the backslash in the regex too:

- name: Remove LE webroot definition
    lineinfile: 
      path: "/etc/path/to/config/{{ inventory_hostname }}.conf"
      regexp: "^{{ inventory_hostname | replace('.', '\\.') }} = /path/to/a/directory"
      state: absent