Parse error in sudoers file

A "sudo: parse error in ..." originating from /etc/sudoers or any of the files included with either the #include <filename> or #includedir <path> directives may be caused by a missing new-line on the last entry in that file.


Using the copy module is probably not the best choice to handle /etc/sudoers with Ansible.

The lineinfile module has an option to validate the file before saving. It is also easier to remove the line, etc with that module.

The documentation contains an example how to use it.

- name: Set up password-less sudo for kafka user
  lineinfile: dest=/etc/sudoers state=present regexp='^%{{ kafka_user }} ALL\=' line='%{{ kafka_user }} ALL= NOPASSWD: /etc/init.d/{{ kafka_service_name }}' validate='visudo -cf %s'