0

I am having issues concatenating strings in Salt, I want to grab a salt grain called "accesslist" which holds an array of groups to append to an access list.

     {% set access_filter = '(memberOf=CN=bbb,OU=Security,OU=Groups,OU=yyy,DC=xxx,DC=local)' %}    
     {% for acc in grains.accesslist %}
     {% set access_filter = '(memberOf=CN={{ acc }},OU=Security,OU=Groups,OU=aa,DC=bb,DC=local)' ~ access_filter %}
            {{ acc }}_call_off:
                cmd.run:
                    - name: echo {{ acc }}
{% endfor %}

I thought it was an issue with the grains, or itterator, but I was able to confirm it's pulling the array in and able to break out the


      ID: test_call_off
Function: cmd.run
    Name: echo test
  Result: True
 Comment: Command "echo test" run
 Started: 10:59:32.641942
Duration: 7.182 ms
 Changes:   
          ----------
          pid:
              375233
          retcode:
              0
          stderr:
          stdout:
              test

      ID: test2_call_off
Function: cmd.run
    Name: echo test2
  Result: True
 Comment: Command "echo test2" run
 Started: 10:59:32.649277
Duration: 3.948 ms
 Changes:   
          ----------
          pid:
              375234
          retcode:
              0
          stderr:
          stdout:
              test2

      ID: create_access_list
Function: file.append
    Name: /etc/sssd/conf.d/ccom_sssd_configs.conf
  Result: True
 Comment: File /etc/sssd/conf.d/ccom_sssd_configs.conf is in correct state
 Started: 10:59:32.655181
Duration: 14.477 ms
 Changes:   
1
  • You're not using the access_filter after you set it...
    – OrangeDog
    Apr 2 at 21:18

1 Answer 1

0

{{ }} declares a jinja context, but you are trying to use it when you're already in a jinja context. Instead, use the concatenation operator: ~.

Also, avoid aliasing variables in inner scopes.

{% set shared_filter = '(memberOf=CN=bbb,OU=Security,OU=Groups,OU=yyy,DC=xxx,DC=local)' %}    
{% for acc in grains['accesslist'] %}
{% set access_filter = '(memberOf=CN=' ~ acc ~ ',OU=Security,OU=Groups,OU=aa,DC=bb,DC=local)' ~ shared_filter %}
{{ acc }}_call_off:
  test.show_notification:
    - text: {{ access_filter }}
{% endfor %}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .