This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
---
|
||||
- name: Deploy DevOps application
|
||||
hosts: targets
|
||||
become: true
|
||||
|
||||
vars:
|
||||
deploy_image: "mikhaillobanov/devops-platform:latest"
|
||||
|
||||
tasks:
|
||||
- name: Create application directory
|
||||
ansible.builtin.file:
|
||||
path: /opt/devops-platform
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0755'
|
||||
|
||||
- name: Copy Docker Compose configuration
|
||||
ansible.builtin.copy:
|
||||
src: "{{ playbook_dir }}/../../compose.yaml"
|
||||
dest: /opt/devops-platform/compose.yaml
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
|
||||
- name: Deploy application with Docker Compose
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose up -d --pull always
|
||||
chdir: /opt/devops-platform
|
||||
environment:
|
||||
IMAGE: "{{ deploy_image }}"
|
||||
register: deploy_result
|
||||
changed_when: >
|
||||
'Created' in deploy_result.stdout or
|
||||
'Started' in deploy_result.stdout or
|
||||
'Pulled' in deploy_result.stdout or
|
||||
'Recreated' in deploy_result.stdout
|
||||
|
||||
- name: Wait for application health endpoint
|
||||
ansible.builtin.uri:
|
||||
url: http://127.0.0.1:8000/health
|
||||
method: GET
|
||||
status_code: 200
|
||||
return_content: true
|
||||
register: health_result
|
||||
retries: 10
|
||||
delay: 3
|
||||
until: health_result.status == 200
|
||||
|
||||
- name: Show deployed image
|
||||
ansible.builtin.debug:
|
||||
msg: "Deployed image: {{ deploy_image }}"
|
||||
|
||||
- name: Show application health
|
||||
ansible.builtin.debug:
|
||||
var: health_result.json
|
||||
Reference in New Issue
Block a user