Ansible parse variables with special characters

14 views
Skip to first unread message

pnagar...@gmail.com

unread,
Jan 28, 2019, 12:31:04 PM1/28/19
to Ansible Project
I need to pass certain strings with special characters like $ to variables.
I was able to parse by providing the values in single quotes or using \ when the string contains a single $ .

Ex below x is my variable.

X : '${name}' --> this works.

But when my variable value is complex containing many $ in its value, it doesn't parse it.

Example :
X : '${name} --loglevel = ${loglevel}, --type=${type}'

The above is a shortend version but actually has many $ in the same format like above.
I tried using \ for every $ but it didn't help.

Is there a way to parse them ?

Kai Stian Olstad

unread,
Jan 28, 2019, 12:48:15 PM1/28/19
to ansible...@googlegroups.com
I got no problem with this so I think you need to explain more in detail
what you are doing.

$ cat test.yml
---
- hosts: localhost
vars:
x: '${name} --loglevel = ${loglevel}, --type=${type}'
tasks:
- debug: msg="{{ x }}"

$ ansible-playbook test.yml
PLAY [localhost]
***************************************************************

TASK [debug]
*******************************************************************
ok: [localhost] => {}

MSG:

${name} --loglevel = ${loglevel}, --type=${type}


PLAY RECAP
*********************************************************************
localhost : ok=1 changed=0 unreachable=0
failed=0


In this example you don't even need the single quotes to make it work.

--
Kai Stian Olstad

Eric Dunn

unread,
Jan 28, 2019, 4:48:36 PM1/28/19
to ansible...@googlegroups.com
I had ame issue.
Try escaping dollar sign

X : '\${name} --loglevel = \${loglevel}, --type=\${type}' 


Thank you,

Eric Dunn
 
Senior DevOPS Support Engineer
 
 
IPConfigure, Inc
t: 877-207-1112 ext. 104
e: eric...@ipconfigure.com
 
www.ipconfigure.com
 


The content of this email is confidential and intended for the recipient specified in message only. It is strictly forbidden to share any part of this message with any third party, without a written consent of the sender. If you received this message by mistake, please reply to this message and follow with its deletion, so that we can ensure such a mistake does not occur in the future.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/95e4d0ed-f6d7-4a60-b283-470a18273c79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages