Salt: mapping values not allowed in states

Created on 23 Jan 2016  路  6Comments  路  Source: saltstack/salt

## configure user.name and user.email for git repositorie
salt.master::repo:
  git.config_set:
    - repo: /srv/salt/states
    - value: salt
    - names:
        - user.name
        - user.email
            - value: salt@{{ salt.grains.get('fqdn') }}

The above should be allowed according the docs: https://docs.saltstack.com/en/latest/ref/states/highstate.html#names-declaration

local:
    Data failed to compile:
----------
    Rendering SLS 'base:salt.master' failed: mapping values are not allowed here; line 36

---
[...]
    - repo: /srv/salt/states
    - value: salt
    - names:
        - user.name
        - user.email
            - value: [email protected]    <======================

# vim: tabstop=2 expandtab shiftwidth=2 softtabstop=2

---

Most helpful comment

Try with a colon at the end of user.email. Looks to be missing based on the example in the doc...

## configure user.name and user.email for git repositorie
salt.master::repo:
  git.config_set:
    - repo: /srv/salt/states
    - value: salt
    - names:
        - user.name
        - user.email:                                      # <----------------------- colon
            - value: salt@{{ salt.grains.get('fqdn') }}

All 6 comments

Still using super fresh develop branch, from yesterday evening

Try with a colon at the end of user.email. Looks to be missing based on the example in the doc...

## configure user.name and user.email for git repositorie
salt.master::repo:
  git.config_set:
    - repo: /srv/salt/states
    - value: salt
    - names:
        - user.name
        - user.email:                                      # <----------------------- colon
            - value: salt@{{ salt.grains.get('fqdn') }}

Yep, that did the trick!

Running yamllint on state (*.sls) files is helpful for identifying these syntax issues. Acknowledging and understanding not all states are static YAML and more complex Salt deployments will have dynamic state files (ex. Jinja2 templates).

Is there a process (Salt or other) to render the static YAML result? At that point yamllint would be an option.

Edit: updated for templates

yamllint does not work with jinja involved.

Hi @SteffenKockel ,

Ran into an errant YAML character I could not find in a Jinja2 template recently too. This code helped finding my issue:

#!/usr/bin/env python3

import yaml
import sys
import logging
import os
from jinja2 import Environment, FileSystemLoader

__project__ = os.path.basename(os.path.dirname(__file__))
__localrepo__ = os.path.dirname(os.path.dirname(__file__))
__templates__ = os.path.join(__localrepo__, 'states')

__format__ = '%(levelname)s:PID%(process)d:%(name)s:%(filename)s:line %(lineno)d:%(funcName)s:%(message)s'  # w/o time
__formatter__ = logging.Formatter(__format__)
__console__ = logging.StreamHandler()
__console__.setFormatter(__formatter__)

LOG = logging.getLogger(__project__)
LOG.handlers = []
LOG.addHandler(__console__)
LOG.setLevel(10)

if __name__ == "__main__":
    env = Environment(autoescape=False,
                      trim_blocks=True,
                      keep_trailing_newline=True,
                      loader=FileSystemLoader(__templates__))

    try:
        # Read command line options, select first one - expecting a file name in dir ../states
        salt_state_file_name = sys.argv[1]
        # Can we create a Jinja2 template from the file?
        template = env.get_template(salt_state_file_name)
        # Can we render a Jinja2 template from the file?
        salt_state_rendered = template.render()
        # Log rendered Jinja2 template for review; requires LOG.setLevel(10)
        LOG.debug(' rendered:\n{}'.format(salt_state_rendered))
        # Can we deserialize the Jinja2 template as YAML?
        salt_state_deserialized = yaml.load(salt_state_rendered, Loader=yaml.SafeLoader)
        # Log logically equivalent YAML for review; requires LOG.setLevel(10)
        LOG.debug(' (de/re)serialized:\n{}'.format(yaml.dump(salt_state_deserialized, default_flow_style=False)))
    except Exception as err:
        LOG.error(err)

    pass  # set breakpoint for debugger here

Hpe you find this helpful. Basic usage is check_state.py FILENAME.

Ciao,
Jason

Was this page helpful?
0 / 5 - 0 ratings