SSAR
SSAR

Reputation: 33

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: networking.k8s.io/v1
      namespace: "{{namespace}}"
      definition:
        kind: Ingress
        metadata:
          name: "{{namespace}}-ingress"
          annotations:
             nginx.ingress.kubernetes.io/backend-protocol: HTTP
             nginx.ingress.kubernetes.io/auth-url: "https://$host/oauth2/auth"
             nginx.ingress.kubernetes.io/auth-signin: "https://$host/oauth2/start?rd=$escaped_request_uri"
             nginx.ingress.kubernetes.io/force-ssl-redirect: 'false'
             nginx.ingress.kubernetes.io/hsts: 'false'
             nginx.ingress.kubernetes.io/ssl-redirect: 'false'
             nginx.ingress.kubernetes.io/websocket-services: core-service
             nginx.org/websocket-services: 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:

          nginx.ingress.kubernetes.io/auth-url: "https://$host/oauth2/auth"
                                              ^ 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"

Upvotes: 3

Views: 10756

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 68254

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.

Upvotes: 2

Related Questions