1

I'm developing a automatic proftpd installation whit Salt. I won't to get the ftp users from a template but I can't get work the pillar. I initialized the pillar whit the users data and call it into a for loop, but y don't get the pillar user data in the loop.

When I make salt-call pillar.get ftpusers in the minion, the response is:

local:

This is my pillar ftpusers.sls:

ftp-server.ftpusers:
  user:
    - user: user
    - passhash: j2k3hk134123l1234ljh!"·$ser
    - uuid: 1001
    - guid: 1001
    - home: /srv/ftp/user
    - shel: /bin/false

And this is the for loop:

{% for users in pillar.get('ftpusers', {}).items() %}

  /srv/herma-ftp/.ftpusers:
    file.managed:
      - user: root
      - group: root
      - mode: 444
      - contents:'{{ user }}:{{ args['passhash'] }}:{{args['uuid'] }}:{{ args['guid'] }}::{{ args['home'] }}:{{ args['shel'] }}'
      - require:
        - file: /srv/herma-ftp

  /srv/herma-ftp/{{user}}:
    file.directory:
      - user: nobody
      - group: nobody
      - dir_mode: 775
      - makedirs: True
      - require:
        - file: /srv/herma-ftp
      - watch:
        - file: /srv/herma-ftp
    module.run:
      - name: file.set_selinux_context
      - path: {{ args['home']}}
      - type: public_content_t
      - unless:
        - stat -c %C {{ args['home'] }} |grep -q public_content_t

{% endfor %}

When I make in the minion

salt-call -l debug state.sls herma-ftp-server saltenv=My-enviroment test=True

Don't expect this for because don't can get the pillar data.

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
  • checkout the salt-users formula at https://github.com/saltstack-formulas/users-formula/blob/master/users/init.sls#L5 (and pillar example https://github.com/saltstack-formulas/users-formula/blob/master/pillar.example), also noted that you can't have "/srv/herma-ftp/.ftpusers:..." in your loops since it will create duplicate ids – number5 Dec 01 '14 at 05:08

1 Answers1

2

You should notice that pillars works like dictionaries. In you current syntax, to access to the pillar the key name is "ftp-server.ftpusers", not ftpusers. If you want the information in a hierarchy the usual approach is:

ftp-server:
 ftpusers:
   user:
    - user: user
    - passhash: j2k3hk134123l1234ljh!"·$ser
    - uuid: 1001
    - guid: 1001
    - home: /srv/ftp/user
    - shel: /bin/false

Then in the template:

{%- set ftp-server = pillar.get("ftp-server", {}) %}
{%- for users in ftp-server.get('ftpusers', {}).items() %}
{%- do_something() %}
{%- endfor %}
Diego Woitasen
  • 931
  • 5
  • 11