--- # Application deployment playbook # Usage: ansible-playbook -i inventory/production playbooks/deploy.yml - name: Deploy application hosts: webservers become: true serial: 1 vars: app_version: "{{ app_version | default('latest') }}" tasks: - name: Display deployment info debug: msg: | Deploying {{ app_name }} version {{ app_version }} To: {{ inventory_hostname }} tags: ['always'] - name: Create application directory file: path: "{{ app_dir }}" state: directory owner: "{{ app_user }}" group: "{{ app_group }}" mode: '0755' tags: ['setup'] - name: Deploy sample HTML copy: dest: "{{ app_dir }}/index.html" content: | {{ app_name }}

🚀 {{ app_name }}

Version: {{ app_version }}

Server: {{ inventory_hostname }}

Environment: {{ environment }}

owner: "{{ app_user }}" group: "{{ app_group }}" mode: '0644' tags: ['deploy'] - name: Restart Nginx service: name: nginx state: restarted tags: ['restart'] - name: Verify deployment uri: url: "http://{{ ansible_host }}" status_code: 200 delegate_to: localhost become: false tags: ['verify']