Compare commits

..

5 commits

Author SHA1 Message Date
d7e6a95f1e Update docker.io/library/postgres Docker tag to v18
Some checks failed
/ Ansible Lint (push) Failing after 2m35s
/ Ansible Lint (pull_request) Failing after 2m36s
2025-11-04 01:45:50 +00:00
ae60d6fea6
docker_compose(role): use community.docker.docker_compose_v2 module
Some checks failed
/ Ansible Lint (pull_request) Failing after 2m12s
/ Ansible Lint (push) Failing after 1m57s
Use the community.docker.docker_compose_v2 module as it supports proper
changed handling out of the box, making the roles code more
straightforward and work. Also just do a docker compose restart instead
of having the custom docker compose reload script.

https://docs.ansible.com/ansible/latest/collections/community/docker/docker_compose_v2_module.html
2025-11-02 23:13:20 +01:00
9f8d2d89cd
docker_compose(role): move argument documentation to README
Do this to match newer roles and since reading documentation from
argument_specs is quite unergonomic.
2025-11-02 22:32:20 +01:00
e390b7c202
docker_compose(role): remove unnecessary hosts section from README
The hosts section isn't really relevant for that role, so remove it.
2025-11-02 22:32:20 +01:00
8cefd07618
docker_compose(role): remove distribution check
The distribution check isn't really needed in our setup anyway and just
adds unnecessary noise.
2025-11-02 22:32:20 +01:00
8 changed files with 28 additions and 72 deletions

View file

@ -6,4 +6,3 @@ docker_compose__configuration_files:
content: "{{ lookup('ansible.builtin.template', 'resources/z9/yate/docker_compose/regexroute.conf.j2') }}" content: "{{ lookup('ansible.builtin.template', 'resources/z9/yate/docker_compose/regexroute.conf.j2') }}"
- name: regfile.conf - name: regfile.conf
content: "{{ lookup('ansible.builtin.template', 'resources/z9/yate/docker_compose/regfile.conf.j2') }}" content: "{{ lookup('ansible.builtin.template', 'resources/z9/yate/docker_compose/regfile.conf.j2') }}"
docker_compose__restart_cmd: "exec yate sh -c 'kill -1 1'"

View file

@ -6,3 +6,6 @@ collections:
- name: community.sops - name: community.sops
version: ">=2.2.4" version: ">=2.2.4"
source: https://galaxy.ansible.com source: https://galaxy.ansible.com
- name: community.docker
version: ">=5.0.0"
source: https://galaxy.ansible.com

View file

@ -7,17 +7,18 @@ A use case for the deployment of the additional configuration files is Composes
## Supported Distributions ## Supported Distributions
The following distributions are supported: Should work on Debian-based distributions.
- Debian 11
## Required Arguments ## Required Arguments
For the required arguments look at the [`argument_specs.yaml`](./meta/argument_specs.yaml). - `docker_compose__compose_file_content`: The content to deploy to the Compose file at `/ansible_docker_compose/compose.yaml`.
## `hosts` ## Optional Arguments
The `hosts` for this role need to be the machines, for which you want to make sure the given Compose file is deployed and all services of it are up-to-date and running. - `docker_compose__env_file_content`: The content to deploy to the `.env` file at `/ansible_docker_compose/.env`.
- `docker_compose__configuration_files`: A list of configuration files to deploy to the `/ansible_docker_compose/configs/` directory.
- `docker_compose__configuration_files.*.name`: The name of the configuration file.
- `docker_compose__configuration_files.*.content`: The content to deploy to the configuration file.
## Links & Resources ## Links & Resources

View file

@ -1,2 +1 @@
docker_compose__configuration_files: [ ] docker_compose__configuration_files: [ ]
docker_compose__restart_cmd: ""

View file

@ -1,13 +1,11 @@
- name: docker compose down - name: docker compose down
ansible.builtin.command: community.docker.docker_compose_v2:
cmd: /usr/bin/docker compose down project_src: /ansible_docker_compose
chdir: /ansible_docker_compose state: absent
become: true become: true
changed_when: true # This is always changed.
- name: docker compose reload script - name: docker compose restart
ansible.builtin.command: community.docker.docker_compose_v2:
cmd: /usr/bin/docker compose {{ docker_compose__restart_cmd }} project_src: /ansible_docker_compose
chdir: /ansible_docker_compose state: restarted
become: true become: true
changed_when: true # Mark this as always changed (for now?).
when: docker_compose__restart_cmd != ""

View file

@ -2,31 +2,20 @@ argument_specs:
main: main:
options: options:
docker_compose__compose_file_content: docker_compose__compose_file_content:
description: >-
The content of the Compose file at
`/ansible_docker_compose/compose.yaml`.
type: str type: str
required: true required: true
docker_compose__env_file_content: docker_compose__env_file_content:
description: >-
The content of the .env file at
`/ansible_docker_compose/.env`.
type: str type: str
required: false required: false
docker_compose__configuration_files: docker_compose__configuration_files:
description: >-
A list of configuration files to be deployed in the
`/ansible_docker_compose/configs/` directory.
type: list type: list
elements: dict elements: dict
required: false required: false
default: [ ] default: [ ]
options: options:
name: name:
description: The name of the configuration file.
type: str type: str
required: true required: true
content: content:
description: The content of the configuration file.
type: str type: str
required: true required: true

View file

@ -1,10 +1,3 @@
--- ---
dependencies: dependencies:
- role: distribution_check
vars:
distribution_check__distribution_support_spec:
- name: Debian
major_versions:
- 11
- 12
- role: docker - role: docker

View file

@ -59,7 +59,7 @@
state: absent state: absent
become: true become: true
loop: "{{ docker_compose__config_files_to_remove.files }}" loop: "{{ docker_compose__config_files_to_remove.files }}"
# notify: docker compose down notify: docker compose restart
- name: make sure all given configuration files are deployed - name: make sure all given configuration files are deployed
ansible.builtin.copy: ansible.builtin.copy:
@ -70,45 +70,19 @@
group: root group: root
become: true become: true
loop: "{{ docker_compose__configuration_files }}" loop: "{{ docker_compose__configuration_files }}"
# notify: docker compose down notify: docker compose restart
notify: docker compose reload script
- name: Flush handlers to make "docker compose down" handler run now - name: Flush handlers to make "docker compose down" and "docker compose restart" handlers run now
ansible.builtin.meta: flush_handlers ansible.builtin.meta: flush_handlers
- name: docker compose ps --format json before docker compose up - name: docker compose up
ansible.builtin.command: community.docker.docker_compose_v2:
cmd: /usr/bin/docker compose ps --format json project_src: /ansible_docker_compose
chdir: /ansible_docker_compose state: present
build: always
pull: always
remove_orphans: true
become: true become: true
changed_when: false
register: docker_compose__ps_json_before_up
- name: docker compose up --detach --pull always --build
ansible.builtin.command:
cmd: /usr/bin/docker compose up --detach --pull always --build --remove-orphans
chdir: /ansible_docker_compose
become: true
changed_when: false
# The changed for this task is tried to be determined by the "potentially
# report changed" task together with the "docker compose ps --format json
# [...]" tasks.
- name: docker compose ps --format json after docker compose up
ansible.builtin.command:
cmd: /usr/bin/docker compose ps --format json
chdir: /ansible_docker_compose
become: true
changed_when: false
register: docker_compose__ps_json_after_up
# Doesn't work anymore. Dunno why.
# TODO: Fix
# - name: potentially report changed
# ansible.builtin.debug:
# msg: "If this reports changed, then the docker compose containers changed."
# changed_when: (docker_compose__ps_json_before_up.stdout | from_json | community.general.json_query('[].ID') | sort)
# != (docker_compose__ps_json_after_up.stdout | from_json | community.general.json_query('[].ID') | sort)
- name: Make sure anacron is installed - name: Make sure anacron is installed
become: true become: true