iac/ansible/playbooks/deploy-docker.yml

34 lines
967 B
YAML
Raw Normal View History

---
- name: Deploy application
hosts: "{{ target_host }}"
vars:
repo_path: "/home/{{ ansible_user }}/iac/docker/{{ folder }}"
tasks:
- name: Ensure the repository is up-to-date
ansible.builtin.shell: git pull
args:
chdir: "{{ repo_path }}"
register: git_pull_output
- name: Display git pull output
ansible.builtin.debug:
var: git_pull_output.stdout_lines
- name: Restart services using Docker Compose
community.docker.docker_compose_v2:
project_src: "{{ repo_path }}"
state: present
remove_orphans: true
register: docker_compose_output
- name: Display container states
debug:
msg: |
Container {{ item.Names[0] }}
- State: {{ item.State }}
- Status: {{ item.Status }}
- Ports: {{ item.Ports }}
- Networks: {{ item.Networks | join(', ') }}
with_items: "{{ docker_compose_output.containers }}"