How do I properly escape a colon in a lineinfile string

I want to add an alias to the end of my /etc/aliases file.

I’ve tried

action: lineinfile dest=“/etc/aliases” backup=yes state=present insertafter=EOF line=“root: unixadmin@example.com

action: lineinfile dest=“/etc/aliases” backup=yes state=present insertafter=EOF line=‘root: unixadmin@example.com

I’m tripping on the colon after root.

Thanks in advance

DT

Another attempt and full error message

  • name: add email alias to /etc/alias
    action: lineinfile dest=“/etc/aliases” backup=yes state=present insertafter=EOF line=“root’:’ unixadmin@example.com

results in

Person who should get root’s mail

#root: marc
root’:’ unixadmin@example.com

which is nicely quoted but not correct.

DT

Sorry,
Error message is as follows.

ERROR: Syntax Error while loading YAML script, prdscmappl01
Note: The error may actually appear before this position: line 28, column 95

  • name: add email alias to /etc/alias
    action: lineinfile dest=“/etc/aliases” backup=yes state=present insertafter=EOF line=“root: unixadmin@example.com
    ^
    This one looks easy to fix. There seems to be an extra unquoted colon in the line
    and this is confusing the parser. It was only expecting to find one free
    colon. The solution is just add some quotes around the colon, or quote the
    entire line after the first colon.

For instance, if the original line was:

copy: src=file.txt dest=/path/filename:with_colon.txt

It can be written as:

copy: src=file.txt dest=‘/path/filename:with_colon.txt’

Or:

copy: ‘src=file.txt dest=/path/filename:with_colon.txt’

Colons need to be added like so…
insertafter=EOF line=“root: unix...@example.com

would be as below
insertafter=EOF line=“root{{ ‘:’ }} unix...@example.com