Documentation for writing SLS files in JSON and salt stack docs in general

1,088 views
Skip to first unread message

Mark van der Walle

unread,
Sep 18, 2014, 8:42:39 AM9/18/14
to salt-...@googlegroups.com
Hi,

We are relying heavily on using JSON as a format for communication between services and for configuration. Now we are exploring the use of salt stack as our central configuration management system and replacing the hacked together scripts and tools. I would like to write the SLS files in JSON. I know this is possible, but it is alot of trial and error, since there are zero examples or guidelines for it.

In general I find the documentation for saltstack quite lacking as it's focus seems to be on cramming in more and more and more features while the documentation is falling behind more and more. It forces us to spend a lot of time to get simple things done. Is it only me that sees this as a problem?

Regards,
Mark

Daniel Bryan

unread,
Sep 18, 2014, 8:51:44 AM9/18/14
to salt-...@googlegroups.com
Syntatically, YAML is a superset of JSON[1]. YAML is the dominant language for SLS files in Salt.

So there's nothing to stop you from filling your state and pillar files with as much ugly JSON as you want; you're still writing in the first-class SLS format which has the best support in Salt and is the most clearly documented.

[1] http://yaml.org/spec/1.2/spec.html#id2759572

Mark van der Walle

unread,
Sep 18, 2014, 9:04:20 AM9/18/14
to salt-...@googlegroups.com
And that is exactly the kind of answer I can't do anything with. I know YAML and JSON both. My problem is that when you add a JSON renderer add a bit more docs on how to use it. No there is nothing stopping me from writing JSON, however there is a lot holding us back.

That YAML is the best supported language does not mean everyone wants to use it. Salt should help differing types of companies to integrate their tools and preferences. It's flexibility in allowing people to use their own language is great.

On a related note. Can the top.sls file be in JSON? I have not found a way to get that to work. It is not actually something that we really need, however I would like to do so for consistency.

Akilesh K

unread,
Sep 18, 2014, 9:57:31 AM9/18/14
to salt-...@googlegroups.com, ma...@crowdynews.com
Hi,
I could not have a top.sls in json. I had that problem too.

@mark
I have a github repo for where I have both yaml and equivalent json syntax sls files in different branches. I hope that helps you.
Further I relied a lot on 'http://jsontoyaml.com/' and 'http://yamltojson.com/' and 'jsonlint.com' to get thing right the first time.

Good luck.

--
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.

Mark van der Walle

unread,
Sep 18, 2014, 10:15:06 AM9/18/14
to Akilesh K, salt-...@googlegroups.com
That helps a lot thank you. Still it would take a lot of time to write it first in YAML, test, convert to JSON, test again.

Do you have any small examples I could look at to get some idea?

Regards,
Mark

Senior DevOps Engineer

crowdynews.com
213-B, Friesestraatweg
NL-9743 AD GRONINGEN
The Netherlands
Chamber of Commerce # 02096214

Mail ma...@crowdynews.com
Skype crowdymark

Benjamen Keroack

unread,
Sep 18, 2014, 12:03:07 PM9/18/14
to salt-...@googlegroups.com, akile...@gmail.com
JSON and YAML are just representations of basic data structures (in Python they'd be called dictionaries, lists and strings).

Perhaps the easiest way would be to write your data in YAML, load it in python, then write it out in JSON. In most instances the native Python representation is close enough to JSON that you might not need to do the second conversion:

$ python
>>> import yaml, json
>>> data = yaml.load(open('myfile.yaml', 'r').read(-1))
>>> print(data)
>>> json.dumps(data)

You'll find that a lot of idiomatic salt states are a little more awkward in JSON vs YAML (eg, state options are lists of single-key dictionaries), but once you see the pattern it's pretty easy to convert between them.

Daniel Bryan

unread,
Sep 21, 2014, 6:39:28 PM9/21/14
to salt-...@googlegroups.com
On 18 September 2014 23:04, Mark van der Walle <ma...@crowdynews.com> wrote:
And that is exactly the kind of answer I can't do anything with. I know YAML and JSON both. My problem is that when you add a JSON renderer add a bit more docs on how to use it. No there is nothing stopping me from writing JSON, however there is a lot holding us back.

I might not have been clear.

Being a strict superset of JSON, if you need to write your state files in JSON they will be 100% compatible with the YAML parser.

I can't speak for the salt team's reasons to include a JSON renderer and I haven't looked at what it does. What I know is that you can write your YAML as if it was JSON to your heart's content, it will validate and the default renderer will work with it.

Bruce Wang

unread,
Sep 21, 2014, 8:50:46 PM9/21/14
to salt-...@googlegroups.com
Mark I think this might help http://yamltojson.com/
Try to convert your yaml sls to see what the equivalent json looks like. 

--
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.

Mark van der Walle

unread,
Sep 25, 2014, 3:27:06 AM9/25/14
to salt-...@googlegroups.com, br...@brucewang.net
I have been using yamltojson.com and made some sls files. I think the bigger problem is that I am uncomfortable writing sls files in any format.
Reply all
Reply to author
Forward
0 new messages