2023-12-03 21:56:21 +00:00
|
|
|
---
|
|
|
|
# task/install file for docker_systemd_service
|
2024-11-09 10:04:13 +00:00
|
|
|
- name: "Docker systemd service | Create ENV file(s) for docker service(s)"
|
2023-12-04 22:10:02 +00:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: env.j2
|
|
|
|
dest: "{{ docker_systemd_service_sysconf_dir }}/{{ docker_systemd_service_container_name }}"
|
2023-12-03 21:56:21 +00:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0600'
|
2024-11-09 10:04:13 +00:00
|
|
|
register: _docker_systemd_service_env_file
|
2023-12-03 21:56:21 +00:00
|
|
|
|
2024-11-09 10:04:13 +00:00
|
|
|
- name: "Docker systemd service | Pull docker image(s)"
|
2023-12-04 22:10:02 +00:00
|
|
|
community.docker.docker_image:
|
|
|
|
name: "{{ docker_systemd_service_image }}"
|
|
|
|
force_source: "{{ docker_systemd_service_container_pull_force_source | bool }}"
|
2023-12-03 21:56:21 +00:00
|
|
|
source: pull
|
2024-11-09 10:04:13 +00:00
|
|
|
register: _docker_systemd_service_image_pull
|
2023-12-04 22:10:02 +00:00
|
|
|
when: docker_systemd_service_container_pull_image
|
2023-12-03 21:56:21 +00:00
|
|
|
|
2024-11-09 10:04:13 +00:00
|
|
|
- name: "Docker systemd service | Create unit file(s) for service(s)"
|
2023-12-04 22:10:02 +00:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: unit.j2
|
|
|
|
dest: "/etc/systemd/system/{{ docker_systemd_service_name }}.service"
|
2023-12-03 21:56:21 +00:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
2024-11-09 10:08:56 +00:00
|
|
|
register: _docker_systemd_service_unit_file
|
2023-12-03 21:56:21 +00:00
|
|
|
|
2024-11-09 10:04:13 +00:00
|
|
|
- name: "Docker systemd service | Set reload-check & restart-check variable"
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
_docker_systemd_service_need_daemon_reload: >-
|
|
|
|
{{ _docker_systemd_service_unit_file.changed | bool }}
|
|
|
|
_docker_systemd_service_need_restart: true
|
|
|
|
when: _docker_systemd_service_env_file.changed or
|
|
|
|
_docker_systemd_service_unit_file.changed or
|
|
|
|
docker_systemd_service_container_pull_image.changed
|
|
|
|
|
|
|
|
- name: "Docker systemd service | Enable and start service(s)"
|
2023-12-04 22:10:02 +00:00
|
|
|
ansible.builtin.systemd:
|
|
|
|
name: '{{ docker_systemd_service_name }}.service'
|
2023-12-03 21:56:21 +00:00
|
|
|
daemon_reload: true
|
2023-12-04 22:10:02 +00:00
|
|
|
enabled: "{{ docker_systemd_service_enabled }}"
|
|
|
|
masked: "{{ docker_systemd_service_masked }}"
|
|
|
|
state: "{{ docker_systemd_service_state }}"
|
|
|
|
register: _enable_and_start
|