mapping values are not allowed in this context

116 views
Skip to first unread message

brad.v...@gmail.com

unread,
Jul 12, 2023, 12:29:19 PM7/12/23
to Salt-users
I have a state file which is giving me this error.  Unfortunately, it does not tell me where it is finding the mapping.  I ran it through the yaml renderer, but there are so many line numbers mentioned, I can't tell if any of them are referencing a line in my state file.  Does anyone know of a way to find out where this error is popping up in a state file?

sayf eddine Hammemi

unread,
Jul 12, 2023, 12:37:34 PM7/12/23
to salt-...@googlegroups.com
Hello
this error means generally that your jinja code is producing sth that breaks the YAML rules, most probably a colon `:` that is not escaped which confuses the yaml loader

brad.v...@gmail.com

unread,
Jul 13, 2023, 6:05:32 AM7/13/23
to Salt-users
There is a colon in part of the output, but I then pipe that to a grep -c and to make sure cast the whole thing to int.  The code is attached.  The grep of the log shows something like:
~~~
[12/Jul/2023:14:22:43 +0000] nessuscli invoked with: agent link --key=REDACTED --groups=mygroup>es7 --host=1.2.3.4 --port=8888
~~~
but I then pipe that to a grep -c.  I should just get an integer out of that.  I wish it would at least tell me what line of my code it was on when it encountered the problem.
nessus.txt

Phipps, Thomas

unread,
Jul 13, 2023, 12:53:03 PM7/13/23
to salt-...@googlegroups.com

since the error is a yaml error it most likely wouldn’t help much as what line of code would not correspond to the jinja lined code. but to the rendered yaml code afterwords.

there are two paths forward. first generate the yaml using slsutil.renderer

salt-call slsutil.renderer salt:/path/to/sls.sls default_renderer=jinja

this will give you yaml you can pass through a yaml lint

it will also let you see what the output of just the pure jinja is.

the other path is if you are on 3004 or later. install yamllint into your python on the salt minion and you have a built in yaml renderer. this is only a yaml linter so will break if the jinja is broken

salt-call yaml.lint salt://path/to/sls.sls pre_render=jinja

one thing to note. don’t shell out just to echo when you want to put a message in your states. this is actually a detriment to the system. you are causing more load on the system for a simple message. use the test states. they are both more informative. and can be used to give more depth to the messages.
see https://docs.saltproject.io/en/latest/ref/states/all/salt.states.test.html for the test states. they also can be used for logic within the state tree.


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/0630b4fa-54ad-4149-a03b-40f5072ddc0cn%40googlegroups.com.

Brad Van Orden

unread,
Jul 13, 2023, 1:27:58 PM7/13/23
to salt-...@googlegroups.com
Thanks.   I'll work on those when I get back to work tomorrow. 

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/38LxBZH-5h4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/CAPaX09hbzxMHYUcWQBssRj4%2BD7TAVt3mdPmFCOVpxpQEXJ65qg%40mail.gmail.com.

brad.v...@gmail.com

unread,
Jul 14, 2023, 6:28:57 AM7/14/23
to Salt-users
With the help of yamllint, I was able to figure out where the error was.  That is now fixed.  Thanks so much for the help!
Reply all
Reply to author
Forward
0 new messages