Error: Mapping Values Are Not Allowed in This Context

Following is the code. Verified indentation. Unable to figure out the exact issue.

Code :

 - name: Create K8s ingress
     k8s:
      api_version: 
      namespace: "{{namespace}}"
      definition:
        kind: Ingress
        metadata:
          name: "{{namespace}}-ingress"
          annotations:
              HTTP
              ""
              ""
              'false'
              'false'
              'false'
              core-service
              core-service
        spec:
          rules:
          - host: "{MY_DOMAIN}}"
            http:
              paths:
                - backend:
                   service:
                     name: "wordpress"
                     port:
                       number: 80
                  path: /
                  pathType: ImplementationSpecific

Error : Syntax Error while loading YAML. mapping values are not allowed in this context

The error appears to be in '/mnt/disc2/workspace/wp-sr-demo/auth-playbooks/wordpress/roles/deploy/tasks/main.yml': line 110, column 51, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

           ""
                                              ^ here

This one looks easy to fix. It seems that there is a value started with a quote, and the YAML parser is expecting to see the line ended with the same kind of quote. For instance:

when: "ok" in result.stdout

Could be written as:

when: '"ok" in result.stdout'

Or equivalently:

when: "'ok' in result.stdout"

1

1 Answer

Indentation of the attributes name and k8s is wrong

 - name: Create K8s ingress
     k8s:

The correct indentation of the attributes name and k8s must be the same because they belong to the same dictionary

   - name: Create K8s ingress
     k8s:

If you move the first line two spaces to the right you'll get valid YAML.

3

Your Answer

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

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest