--- - name: Configure Nginx reverse proxy hosts: targets become: true tasks: - name: Deploy Nginx reverse proxy configuration ansible.builtin.template: src: "{{ playbook_dir }}/../templates/devops-platform.conf.j2" dest: /etc/nginx/sites-available/devops-platform owner: root group: root mode: '0644' notify: Reload Nginx - name: Enable DevOps application site ansible.builtin.file: src: /etc/nginx/sites-available/devops-platform dest: /etc/nginx/sites-enabled/devops-platform state: link notify: Reload Nginx - name: Disable default Nginx site ansible.builtin.file: path: /etc/nginx/sites-enabled/default state: absent notify: Reload Nginx - name: Validate Nginx configuration ansible.builtin.command: cmd: nginx -t changed_when: false - name: Apply Nginx changes now ansible.builtin.meta: flush_handlers - name: Verify application through Nginx ansible.builtin.uri: url: http://127.0.0.1/health method: GET status_code: 200 return_content: true register: proxy_health retries: 5 delay: 2 until: proxy_health.status == 200 - name: Show proxied application health ansible.builtin.debug: var: proxy_health.json handlers: - name: Reload Nginx ansible.builtin.service: name: nginx state: reloaded