简体   繁体   English

for循环中的Saltstack负载支柱

[英]Saltstack load pillar in a for loop

I am developing a automatic proftd installation whit Salt, i wont to get the ftp users from a template but I cant get work the pillar, i initialized the pillar whit the users data and call it into a for loop, but you don't get the pillar user data in the loop. 我正在开发Salt的自动proftd安装,我不会从模板获取ftp用户,但是我无法使支柱工作,我将用户数据初始化了支柱,并将其调用为for循环,但是您没有得到循环中的主要用户数据。

When i make salt-call pillar.get ftpusers in the minion, the response is: 当我在奴才中进行Salt-call支柱.get ftpusers时,响应为:

local: 本地:

This is my pillar ftpusers.sls: 这是我的支柱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循环:

{% 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. 不要期望如此,因为无法获取支柱数据。

Your loop should also look like: 您的循环也应如下所示:

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

Also, contents argument for a file.managed doesn't support templating. 同样, file.managed contents参数不支持模板。 What you need to do is move /srv/herma-ftp/.ftpusers state outside of the loop, and make the loop inside the file template. 您需要做的是将/srv/herma-ftp/.ftpusers状态移出循环,然后将循环/srv/herma-ftp/.ftpusers文件模板内。 The final layout of your state should look like: 您状态的最终布局应如下所示:

/srv/herma-ftp/.ftpusers
  file.managed:
    source: salt://ftpserver/dot.ftpusers
    template: jinja
    ...
    ...

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

/srv/herma-ftp/{{user}}:
  file.managed:
    ...

{% endfor %}

And your ftpserver/dot.ftpusers would look like: 和您的ftpserver/dot.ftpusers看起来像:

{% for user, args in pillar.get('ftpusers', {}).items() %}
{{ user }}:{{ args['passhash'] }}:{{args['uuid'] }}:{{ args['guid'] }}::{{ args['home'] }}:{{ args['shel'] }}
{% endfor %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM