Назад | Перейти на главную страницу

Соляной порядок исполнения состояний

Я пытаюсь создать несколько файлов 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

Любая помощь?

Спасибо!

Я бы добавил onlyif к clear_default_config лайк:

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