79

I've browsed similar questions and believe i've applied all that i've been able to glean from answers.

I have a .yml file where as far as I can tell each element is formatted identically. And yet according to YamlLint.com

(<unknown>): mapping values are not allowed in this context at line 119 column 16

In this case, line 119 is the line containing the second instance the word "transitions" below. That I can tell each element is formatted identically. Am I missing something here?

  landingPage:
    include: false
    transitions:
      -
        condition:location
        nextState:location

  location:
    include:false
    transitions:
      -
        condition:excluded
        nextState:excluded

  excluded:
    include:false
    transitions:
      -
        condition:excluded
        nextState: excluded
      -
        condition:age
        nextState:age

9 Answers 9

48

You cannot have a multiline plain scalar, such as your include:false transitions be the key to a mapping, that is why you get the mapping values not allowed in this context error.

Either you forgot that you have to have a space after the value indicator (:), and you meant to do:

        include: false
        transitions:

or you need to quote your multi-line scalar:

        'include:false
        transitions':

or you need to put that plain scalar on one line:

        include:false transitions:

please note that some libraries do not allow value indicators in a plain scalar at all, even if they are not followed by space

24

I fixed this for myself by simply realizing I had indented a line too far, and un-indenting it.

2
  • 1
    Same here. Had an if else block and had a couple spaces on the line under my {{ if }} block which caused this error. Thanks!
    – IT_User
    May 30, 2022 at 17:02
  • 3
    Copied from another file and the indenting was off by 1. I hate yaml.
    – PMac
    Sep 13, 2022 at 10:34
9

we need to use space before ":" Then it will excecute check the yaml script in below http://www.yamllint.com/

1
  • it should be space after ":"
    – arif abbas
    Oct 6, 2023 at 5:33
6

I was working in a Helm chart. My issue was the markup

{{- if .Values.serviceAccount.create -}}
serviceAccountName: {{ include "myapp.serviceAccountName" . }}
{{- end }}

The problem was the - at the end of the if expression. Removing that - resolved the issue

{{- if .Values.serviceAccount.create }}
1
  • I had a similar issue, changing {{- end -}} to {{- end }} did the trick for me.
    – mathieux51
    Jan 30 at 14:59
5

There are couple of issues in the yaml file, with yaml files it gets messy, fortunately it can be identified easily with tools like yaml lint

Install it

npm install -g yaml-lint

Here is how you can validate

E:\githubRepos\prometheus-sql-exporter-usage\etc>yamllint prometheus.yaml
√ YAML Lint successful.
1
  • 1
    I get "YAML Lint successful", but running docker-compose up still throws the same mapping values are not allowed in this context error, so I guess your answer isn't really working for me. Jul 3, 2021 at 21:13
3

For me the problem was a unicode '-' from a cut and paste. Visualy it looked OK, but the character was 'EN DASH' (U+2013) instead of 'HYPHEN MINUS' (U+002D)

2

In mine case it was the space after the : in a value:

query-url: https://blabla.com/blabla?label=blabla: blabla

To fix:

query-url: https://blabla.com/blabla?label=blabla:%20blabla

Or:

query-url: "https://blabla.com/blabla?label=blabla: blabla"
0

If you are using powershell and have copied the cat command, it won't work properly (I'm guessing it is encoding the content in some way). Instead of using "$(cat file.yaml)" you should use $(Get-Content file.yaml -Raw) without the quotes.

Really annoying!

-1

In my case if was some odd disappearing of the initial formatting of the initial chart that was copied in Intellij Idea. It was possible to gfigure out with text-compare tool only:

enter image description here

So, when you do your copy and paste in your IDE, please double check is what you have copied is exactly what you paste, aren't some additional spaces were added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.