Ansible\'s lineinfile gives a syntax error when there\'s a space after colon(:) in the line, like line=\'item: value\'. If there\'s no space like <
lineinfile
line=\'item: value\'
Escape the colon as {{ ":" }}:
{{ ":" }}
- name: set up sudo for testgroup lineinfile: dest=/etc/sudoers line='%testgroup ALL= NOPASSWD{{ ":" }} /sbin/shutdown -r now' state=present insertafter=EOF validate='visudo -cf %s'