各州执行盐令

各州执行盐令

我正在尝试创建一些 nginx 文件,但只能在删除之前 /etc/nginx/sites-enabled 的所有文件之后才能创建。

我有这样的状态:

install_nginx:
  pkg.installed:
    - name: nginx

restart_nginx:
  service:
    - name: nginx
    - running
    - watch:
      - file: /etc/nginx/sites-enabled/*.conf

clear_default_config:
  file.directory:
    - name: /etc/nginx/sites-enabled/
    - clean: True
    - require:
      - pkg: install_nginx

{% for config in salt['pillar.get']('nginx:conf') %}
set_{{ config }}_conf_uncm:
  file.uncomment:
    - name: /etc/nginx/nginx.conf
    - regex: "{{ config }} (.*);$"
    - char: '#'
    - require:
      - file: clear_default_config

set_{{ config }}_conf_repl:
  file.replace:
    - name: /etc/nginx/nginx.conf
    - pattern: "{{ config }} (.*);$"
    - repl: "{{ config }} {{ salt['pillar.get']('nginx:conf:'+config) }};"
    - require:
      - file: clear_default_config
{% endfor %}

问题是,如果创建文件然后又删除它们,这与期望的方式完全相反。

----------
          ID: crear_vhost_testsalt
    Function: file.managed
        Name: /etc/nginx/sites-enabled/testsalt.conf
      Result: True
     Comment: File /etc/nginx/sites-enabled/testsalt.conf updated
     Started: 15:23:26.209494
    Duration: 5.923 ms
     Changes:
              ----------
              diff:
                  New file
              mode:
                  0644
----------
          ID: crear_vhost_testsalt2
    Function: file.managed
        Name: /etc/nginx/sites-enabled/testsalt2.conf
      Result: True
     Comment: File /etc/nginx/sites-enabled/testsalt2.conf updated
     Started: 15:23:26.215843
    Duration: 4.738 ms
     Changes:
              ----------
              diff:
                  New file
              mode:
                  0644
----------
          ID: restart_nginx
    Function: service.running
        Name: nginx
      Result: True
     Comment: Service restarted
     Started: 15:23:26.235859
    Duration: 1033.838 ms
     Changes:
              ----------
              nginx:
                  True
----------
          ID: clear_default_config
    Function: file.directory
        Name: /etc/nginx/sites-enabled/
      Result: True
     Comment: Files cleaned from directory /etc/nginx/sites-enabled
     Started: 15:23:27.270678
    Duration: 1.096 ms
     Changes:
              ----------
              removed:
                  - /etc/nginx/sites-enabled/testsalt2.conf
                  - /etc/nginx/sites-enabled/testsalt.conf

有什么帮助吗?

谢谢!

答案1

我会添加一个类似的onlyif东西clear_default_config

...
- onlyif:
  - "test -f /etc/nginx/sites-enabled/default.conf"

相关内容