59 lines
1.8 KiB
YAML
59 lines
1.8 KiB
YAML
---
|
|
- name: Deploy PPF code
|
|
hosts: ppf
|
|
gather_facts: false
|
|
become: true
|
|
|
|
tasks:
|
|
- name: Sync Python code and support files
|
|
ansible.posix.synchronize:
|
|
src: "{{ ppf_src }}/"
|
|
dest: "{{ ppf_code_dest }}"
|
|
rsync_opts:
|
|
- "--include=*.py"
|
|
- "--include=servers.txt"
|
|
- "--include=Dockerfile"
|
|
- "--exclude=*"
|
|
register: sync_result
|
|
notify: restart containers
|
|
|
|
- name: Deploy compose file
|
|
ansible.builtin.copy:
|
|
src: "{{ ppf_src }}/{{ ppf_compose_src }}"
|
|
dest: "{{ ppf_base }}/compose.yml"
|
|
owner: "{{ ppf_owner }}"
|
|
group: "{{ ppf_owner }}"
|
|
register: compose_result
|
|
notify: restart containers
|
|
|
|
- name: Fix file ownership
|
|
ansible.builtin.file:
|
|
path: "{{ ppf_base }}"
|
|
owner: "{{ ppf_owner }}"
|
|
group: "{{ ppf_owner }}"
|
|
recurse: true
|
|
|
|
- name: Flush handlers before status check
|
|
ansible.builtin.meta: flush_handlers
|
|
|
|
- name: Wait for containers to settle
|
|
ansible.builtin.pause:
|
|
seconds: 2
|
|
when: >-
|
|
ppf_restart | bool and
|
|
(sync_result is changed or compose_result is changed)
|
|
|
|
- name: Check container status
|
|
ansible.builtin.raw: "uid=$(id -u {{ ppf_owner }}) && sudo -u {{ ppf_owner }} bash -c 'export XDG_RUNTIME_DIR=/run/user/'$uid' && cd {{ ppf_base }} && podman-compose ps'"
|
|
register: status_result
|
|
changed_when: false
|
|
|
|
- name: Show container status
|
|
ansible.builtin.debug:
|
|
msg: "{{ status_result.stdout_lines | default([]) }}"
|
|
|
|
handlers:
|
|
- name: restart containers
|
|
ansible.builtin.raw: "uid=$(id -u {{ ppf_owner }}) && sudo -u {{ ppf_owner }} bash -c 'export XDG_RUNTIME_DIR=/run/user/'$uid' && cd {{ ppf_base }} && podman-compose down && podman-compose up -d'"
|
|
when: ppf_restart | bool
|