- name: setup nginx gather_facts: no hosts: "{{target}}" become: "{{become_var}}" vars: brotli: no tasks: - name: check nginx is installed ansible.builtin.shell: executable: /bin/bash cmd: "[[ -x `which nginx` ]]" changed_when: false check_mode: false # single master template for all? #- name: nginx setup # ansible.builtin.template: # src: nginx.conf # dest: /etc/nginx/nginx.conf # mode: 0644 # notify: reload nginx # diff: true - name: host-specific overall nginx config ansible.builtin.template: src: nginx.{{inventory_hostname_short}}.conf dest: /etc/nginx/nginx.conf notify: reload nginx diff: true - name: host-specific nginx vhost configs ansible.builtin.copy: src: "{{ item }}" dest: /etc/nginx/conf.d/{{ item | basename | regex_replace('^[^.]+\.', '') }} with_fileglob: "{{inventory_hostname_short}}.*.conf" notify: reload nginx diff: true handlers: - name: reload nginx ansible.builtin.shell: executable: /bin/bash cmd: "systemctl reload nginx 2>/dev/null || nginx -s reload" - name: restart nginx ansible.builtin.shell: executable: /bin/bash cmd: "systemctl restart nginx 2>dev/null || nginx -s reopen"