Syntax Checking .sls files

1,303 views
Skip to first unread message

ZAM

unread,
Jan 9, 2015, 12:58:48 PM1/9/15
to salt-...@googlegroups.com
I'm sure this has come up before, but I'm looking for a primitive way to do basic syntax checking on my .sls files without having to run through the whole salt-call procedure. I would assume there is something salt does that goes through the jinja2 templating syntax then the yaml syntax.
I looked into kitchen-salt, but it isn't exactly what I want. It seems more robust than I need.  

Atom Powers

unread,
Jan 9, 2015, 1:07:28 PM1/9/15
to salt-...@googlegroups.com
From my understanding you need to load all the grain and pillar data
to compile the templates, because otherwise any of those variables
will be undefined. Using salt-call is the easiest way to do that.

I use this as an mercurial hook.
---
for FILE in $(hg status|grep -e '^\S.sls$') ; do
# File is a path which maps to a state. 'salt/tasks/viewconfig.sls' is
the state 'tasks.viewconfig'
STATE=$(echo $FILE|cut -d'.' -f1|cut -d'/' -f2-|tr '/' '.')
salt-call --local --log-level=error --retcode-passthrough
state.show_sls $STATE
exit=$(($exit + $?))
done
> --
> 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.



--
Perfection is just a word I use occasionally with mustard.
--Atom Powers--

Markus Kramer

unread,
Jan 10, 2015, 8:02:00 AM1/10/15
to salt-...@googlegroups.com
For me, a simulated salt-call would be OK for syntax checking.

But salt-call has no (documented) option to simulate the execution and "--retcode-passthrough" is undocumented.

I find the error message of salt-call hard to read if a syntax error occurs
It would prefer if salt-call gives improved syntax related error messages, not a separate tool.

ZAM, why do you want to avoid "the whole salt-call procedure"?

Oleksandr Yermolenko

unread,
Jan 10, 2015, 10:15:14 AM1/10/15
to salt-...@googlegroups.com
Hi,

to check yaml syntax I use this tool. May it's useful for you too.
http://yaml-online-parser.appspot.com/

Alex
Message has been deleted

Markus Kramer

unread,
Jan 10, 2015, 4:30:03 PM1/10/15
to salt-...@googlegroups.com
Hi Alex,
thank you, but as I said I would rather see this feature integrated into Salt, not as an external tool.

It just happens that I foundFlexGet, and they have it!
FlexGet uses YAML for configuration. This may be confusing (for new users) at first but don't be scared, FlexGet is equipped with validator that tries to guide you if you make mistakes.

So hopefullly a Saltstack Guru reads this, finds this "validator" useful (should be Python) and wants to incorporate it into Salt.

Markus

Charles Baker

unread,
Jan 11, 2015, 12:58:03 PM1/11/15
to salt-...@googlegroups.com
But is salt strictly yaml?

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



--
Charles H. Baker
864.990.1297
Knowing is not enough; we must apply. Willing is not enough; we must do. Bruce Lee

Stephen Spencer

unread,
Jan 11, 2015, 1:07:30 PM1/11/15
to salt-...@googlegroups.com

It is not just yaml, but for a true validation suite to exist for salt, it would have to be able to grok the intent of a defined high state which opens up a whole new universe of complexity.

Metaphysically, you make a good point. In actuality, I believe spending too much time pursuing that thought would take one down a road that would be altogether different than salt's purpose of making *other* systems exists in a consistent and predictable state. :)

-S

pille

unread,
Jan 12, 2015, 2:30:20 PM1/12/15
to salt-...@googlegroups.com
there are at least two tickets in the tracker:

https://github.com/saltstack/salt/issues/802
https://github.com/saltstack/salt/issues/5378

i suggest you comment your ideas on them.

pille

mike r

unread,
Jan 12, 2015, 3:04:35 PM1/12/15
to salt-...@googlegroups.com
This isnt really syntax 'checking', but I use ActiveState Komodo Edit as my Yaml editor, (its a free txt editor), if you go to new > file and select View > View as Language > YAML

it creates a new file, enter your commands and hit Tab to move a level to the right, it enforces the yaml 2-space rule, much easier than using a basic txt editor. 

mike r

unread,
Jan 12, 2015, 3:07:44 PM1/12/15
to salt-...@googlegroups.com
Notepad++ has a YAML syntax as well


On Friday, January 9, 2015 at 12:58:48 PM UTC-5, ZAM wrote:

Zach Mance

unread,
Jan 13, 2015, 4:45:51 PM1/13/15
to salt-...@googlegroups.com
I'd like to avoid the entire "salt-call" procedure, because the way we deploy changes it is exasperating to fix a simple syntax error before deploying the new salt states. 

_ZAM_

--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/qy-ArCbAuyM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.

Atom Powers

unread,
Jan 13, 2015, 4:48:54 PM1/13/15
to salt-...@googlegroups.com
You can run salt-call locally, without a master and before you
check-in to the repository.
Yes, you need to install Salt on your dev system and configure it to
look in the repository, but that shouldn't be too difficult.

Zach Mance

unread,
Jan 13, 2015, 4:56:04 PM1/13/15
to salt-...@googlegroups.com
Hi Atom, I looked at your HG hook, and it seems to make sense. I think for now that will work for now. I will report back to let you know how this worked out for me. I really appreciate the help!

_ZAM_

Stephen Spencer

unread,
Jan 13, 2015, 5:23:13 PM1/13/15
to salt-...@googlegroups.com
The bane of mailing lists: subject lines can't be changed without breaking the thread!

Words mean things.

YAML has no syntax.  It has structure.  So for any(future)one that makes it this far down the thread, you will find nothing regarding actual salt-related syntax validation here.

Zach,

honestly, the only thing I can see that is left to point out is that deploying *anything* to prod without running it through a test environment is an horrifically Bad Idea.  I haven't gotten to the point of needing one yet, but you might check out some of the ways that CI systems are being used to accomplish just this sort of thing.  With all of the various and sundry ways of quickly spinning up dozens of containers/instances/cans/satchels there is not a compelling reason to not do so for the very reasons you have stated.  If you run your state (yes, yes; with salt-call) with -l debug, you will get the file and line number of any structural or  salt module-related error (and fully-rendered templates as an added bonus!)

-S
You know, I used to think it was awful that life was so unfair. Then I thought, wouldn't it be much worse if life were fair, and all the terrible things that happen to us come because we actually deserve them? So, now I take great comfort in the general hostility and unfairness of the universe.
Reply all
Reply to author
Forward
0 new messages