--- - name: Install NGINX & modules package: name: - nginx - libnginx-mod-http-lua - libnginx-mod-http-geoip state: present tags: - role::nginx - name: Copy NGINX default config template: src: default_server.conf dest: /etc/nginx/conf.d/default_server.conf group: root owner: root mode: "0644" tags: - role::nginx notify: - Reload the nginx service - name: Remove default nginx site file: path: /etc/nginx/sites-enabled/default state: absent tags: - role::nginx - name: Copy conf.d entries template: src: "{{ item }}" dest: "/etc/nginx/conf.d/{{ item | basename | splitext | first }}" mode: "0444" owner: root group: root with_fileglob: "../templates/nginx-conf.d/*" loop_control: label: "{{ item | basename | splitext | first }}" tags: - role::nginx notify: - Reload the nginx service - name: Copy host-specific configs copy: content: | # Ansible managed {{ item.value }} dest: "/etc/nginx/sites-available/{{ item.key }}" mode: "0644" group: root owner: root with_items: - "{{ nginx_configs | dict2items }}" tags: - role::nginx when: nginx_configs is defined notify: - Reload the nginx service - name: Enable host-specific sites file: src: "/etc/nginx/sites-available/{{ item }}" dest: "/etc/nginx/sites-enabled/{{ item }}" state: link with_items: - "{{ nginx_configs.keys() }}" tags: - role::nginx when: nginx_configs is defined notify: - Reload the nginx service