0

I got the following sls code which is not working

{% set pillarTree = 'create-login-users_Linux' %}
{% set saltFileSystem = salt['pillar.get']('{{ pillarTree }}:p_metaData:saltFileSystem') %}
{% set userConfigList = salt['pillar.get']('{{ pillarTree }}:p_userData:userConfigList') %}
{% set sftpGroupId = salt['pillar.get']('{{ pillarTree }}:p_userData:loginGroupId') %}

{% if ( grains ['kernel'] == 'Linux' )  %}
#{% for user, args in pillar['users'].items() %}
  {% for user, args in ['userConfigList'].items() %}
    {{ user }}:
      group.present:
        - gid: {{ args['gid'] }}
      user.present:
        - home: {{ args['home'] }}
        - shell: {{ args['shell'] }}
        - uid: {{ args['uid'] }}
        - gid: {{ args['gid'] }}
      {% if 'password' in args %}
        - password: {{ args['password'] }}
      {% if 'enforce_password' in args %}
        - enforce_password: {{ args['enforce_password'] }}
      {% endif %}
      {% endif %}
      - fullname: {{ args['fullname'] }}
      {% if 'groups' in args %}
        - groups: {{ args['groups'] }}
      {% endif %}
      - require:
        - group: {{ user }}
      {% if 'key.pub' in args and args['key.pub'] == True %}
        {{ user }}_key.pub:
        ssh_auth:
          - present
          - user: {{ user }}
          - source: salt://quicken/users/{{ user }}/keys/key.pub
      {% endif %}
  {% endfor %}
{% endif %}

When i run this code in salt from the minion i get :

local:

Data failed to compile:

Rendering SLS 'test:quicken.create-login-user_Linux' failed: Jinja syntax error: Encountered unknown tag 'endblock'. You probably made a nesting mistake. Jinja is expecting this tag, but currently looking for 'endfor' or 'else'. The innermost block that needs to be closed is 'for'.; line 39

[...]

      - present

      - user: {{ user }}

      - source: salt://quicken/users/{{ user }}/keys/key.pub

  {% endif %}

{% endfor %}

{% endblock %} <======================

I want to be able to solve this problem, please help.

1 Answer 1

0

Your issue is most likely the fact that to "comment" the first for loop, you used a #.

But this doesn't have the effect you anticipate: Your for loop is still there.

As consequence, you have two for loop, and only one endfor. This is not correct.

To solve your issue you need to use Jinja comments:

{# for user, args in pillar['users'].items() #}
{% for user, args in ['userConfigList'].items() %}

{# .... #} is the way to comment jinja code.

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