--- - name: Install Nginx apt: name: nginx - name: Create directories for Nginx configuration file: state: directory path: '{{ item }}' mode: 'u=rwx,go=rx' owner: root group: root with_items: - '{{ common__nginx__conf_dir }}' - '{{ common__nginx__confd_dir }}' - '{{ common__nginx__available_dir }}' - '{{ common__nginx__enabled_dir }}' - '{{ common__nginx__snippets_dir }}' notify: common | Restart Nginx - name: Disable Nginx access log lineinfile: path: '{{ common__nginx__conf_dir }}/nginx.conf' regexp: '^(\s*)#?\s*access_log\s+\S+\s*;\s*$' line: '\1#access_log /var/log/nginx/access.log;' backrefs: true notify: common | Restart Nginx - name: Disable Nginx error log lineinfile: path: '{{ common__nginx__conf_dir }}/nginx.conf' regexp: '^(\s*)#?\s*error_log\s+\S+\s*;\s*$' line: '\1#error_log /var/log/nginx/error.log;' backrefs: true notify: common | Restart Nginx - name: Install Nginx log config copy: src: 'files/nginx/syslog.conf' dest: '{{ common__nginx__confd_dir }}/syslog.conf' mode: 'u=rw,go=r' owner: root group: root notify: common | Restart Nginx - name: Remove Nginx default site file: state: absent path: '{{ common__nginx__enabled_dir }}/default' when: common__nginx__remove_default|bool notify: common | Restart Nginx - name: Add Nginx upstreams template: src: 'templates/nginx/upstream.conf' dest: '{{ common__nginx__confd_dir }}/upstream-{{ item.name }}.conf' mode: 'u=rw,go=r' owner: root group: root with_items: '{{ common__nginx__upstreams }}' notify: common | Restart Nginx - name: Add Nginx sites template: src: 'templates/nginx/{{ item.type }}.conf' dest: '{{ common__nginx__available_dir }}/{{ item.domain }}.conf' mode: 'u=rw,go=r' owner: root group: root with_items: '{{ common__nginx__sites }}' notify: common | Restart Nginx - name: Enable Nginx sites file: state: link src: '{{ common__nginx__available_dir }}/{{ item.domain }}.conf' dest: '{{ common__nginx__enabled_dir }}/{{ item.domain }}.conf' owner: root group: root with_items: '{{ common__nginx__sites }}' notify: common | Restart Nginx