Pillar values converted to boolean?

694 views
Skip to first unread message

Benjamen Keroack

unread,
Sep 18, 2014, 2:47:19 PM9/18/14
to salt-...@googlegroups.com
I'm using pillar to populate a configuration file template with values via file.managed in a state. 

The problem I'm having is that the following pillar value is always silently converted to a Python boolean value instead of text:

# pillar value
es_node_data: "true"

# state (partial)
/etc/elasticsearch/elasticsearch.yml:
  file.managed:
  [...]
  - node_data: {{ pillar['es_node_data'] }}
  - template: jinja

# template file (partial)
node.data: {{ node_data }}

# resulting line in file
# should be
# node.data: true

node.data: True

Somehow the value is being converted to a Python True value somewhere and this is getting written to the file. This breaks this configuration file (Elasticsearch) which is case sensitive and requires "true" (not "True").

Any ideas how to fix?

Ben


Alex Leonhardt

unread,
Sep 18, 2014, 2:54:56 PM9/18/14
to salt-...@googlegroups.com

You could use single quotes, I guess, which "should" make it a string...

Alex

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Benjamen Keroack

unread,
Sep 22, 2014, 6:45:50 PM9/22/14
to salt-...@googlegroups.com
Enclosing the values in single quotes didn't work. true/false are still coerced to True/False.

This is super annoying. Am I really going to have to do a file.replace to get rid of the capitals?

Mike Flood

unread,
Sep 22, 2014, 8:38:56 PM9/22/14
to salt-...@googlegroups.com


On Tuesday, September 23, 2014 8:45:50 AM UTC+10, Benjamen Keroack wrote:
Enclosing the values in single quotes didn't work. true/false are still coerced to True/False.



Does wrapping it in a jinja filter work ? e.g.

node.data: {{ lower(node_data) }} 

cheers,

Daniel Jagszent

unread,
Sep 25, 2014, 4:42:45 AM9/25/14
to salt-...@googlegroups.com
Hello Benjamen,


Benjamen Keroack wrote:
Enclosing the values in single quotes didn't work. true/false are still coerced to True/False.

This is super annoying. Am I really going to have to do a file.replace to get rid of the capitals?


this should work. Maybe you placed the single quotes in the wrong place? Alex meant putting them here (marked red and underlined for visibility):

Benjamen Keroack

unread,
Sep 25, 2014, 6:51:09 PM9/25/14
to salt-...@googlegroups.com
This didn't work. The file.replace state immediately afterward still found and replaced the capitals.

Daniel Jagszent

unread,
Sep 26, 2014, 6:48:03 AM9/26/14
to salt-...@googlegroups.com
OK, then pillar['es_node_data'] is already the culprit.
Also add single quotes where you assign 'true' to this pillar value. (and do not drop the ones from my last message)

YAML does some smart interpretation of the data. Whenever you have the values "true/false", "True/False", "yes/no" it will convert those to booleans. When you do not want this to happen you have to use quotes.

26. September 2014 00:51
This didn't work. The file.replace state immediately afterward still found and replaced the capitals.

On Thursday, September 25, 2014 1:42:45 AM UTC-7, Daniel Jagszent wrote:
--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
25. September 2014 10:42
Hello Benjamen,

Benjamen Keroack wrote:
this should work. Maybe you placed the single quotes in the wrong place? Alex meant putting them here (marked red and underlined for visibility):

# state (partial)
/etc/elasticsearch/elasticsearch.yml:
  file.managed:
  [...]
  - node_data: '{{ pillar['es_node_data'] }}'
  - template: jinja

 


23. September 2014 00:45
Enclosing the values in single quotes didn't work. true/false are still coerced to True/False.

This is super annoying. Am I really going to have to do a file.replace to get rid of the capitals?


On Thursday, September 18, 2014 11:54:56 AM UTC-7, Alex Leonhardt wrote:
--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
18. September 2014 20:54

You could use single quotes, I guess, which "should" make it a string...

Alex

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
18. September 2014 20:47
I'm using pillar to populate a configuration file template with values via file.managed in a state. 

The problem I'm having is that the following pillar value is always silently converted to a Python boolean value instead of text:

# pillar value
es_node_data: "true"

# state (partial)
/etc/elasticsearch/elasticsearch.yml:
  file.managed:
  [...]
  - node_data: {{ pillar['es_node_data'] }}
  - template: jinja

# template file (partial)
node.data: {{ node_data }}

# resulting line in file
# should be
# node.data: true

node.data: True

Somehow the value is being converted to a Python True value somewhere and this is getting written to the file. This breaks this configuration file (Elasticsearch) which is case sensitive and requires "true" (not "True").

Any ideas how to fix?

Ben


Benjamen Keroack

unread,
Sep 26, 2014, 1:11:42 PM9/26/14
to salt-...@googlegroups.com
Nice! That worked.

Just to recap: I had to put single quotes around the values both in the file.managed state as well as the pillar values themselves.

Thanks for the help!

Ben
Reply all
Reply to author
Forward
0 new messages