How do I properly escape a colon in a lineinfile string

146 views
Skip to first unread message

Dave Thacker

unread,
Jul 27, 2015, 10:40:11 AM7/27/15
to Ansible Project
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\:        unix...@example.com"
 
action: lineinfile dest="/etc/aliases" backup=yes state=present insertafter=EOF line='root:        unix...@example.com'

I'm tripping on the colon after root.   

Thanks in advance

DT

Dave Thacker

unread,
Jul 27, 2015, 2:38:25 PM7/27/15
to Ansible Project, dtha...@gmail.com
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':'     unix...@example.com"

results in

# Person who should get root's mail
#root:          marc
root':'     unix...@example.com

which is nicely quoted but not correct.   

DT

Dave Thacker

unread,
Jul 27, 2015, 2:41:28 PM7/27/15
to Ansible Project, dtha...@gmail.com
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:     unix...@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'

Larry Smith

unread,
Jul 27, 2015, 4:28:51 PM7/27/15
to Ansible Project, dtha...@gmail.com
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"
Reply all
Reply to author
Forward
0 new messages