diff --git a/playbook.yml b/playbook.yml index 22d5c8c..7bc28a2 100644 --- a/playbook.yml +++ b/playbook.yml @@ -16,4 +16,5 @@ - { role: matrix, tags: ["matrix"] } - { role: iptables, tags: ["iptables"] } - { role: borg, tags: ["borg"] } + - { role: watchtower, tags: ["watchtower"] } - { role: clean, tags: ["clean"] } diff --git a/roles/watchtower/tasks/base.yml b/roles/watchtower/tasks/base.yml new file mode 100644 index 0000000..73aca99 --- /dev/null +++ b/roles/watchtower/tasks/base.yml @@ -0,0 +1,22 @@ +--- + +- name: Check watchtower directory exist + ansible.builtin.file: + path: watchtower + state: directory + +- name: Copy template conf + ansible.builtin.template: + src: "{{ item.src }}" + dest: "watchtower/{{ item.dest }}" + loop: + - { src: 'docker-compose.yml.j2', dest: 'docker-compose.yml' } + register: watchtower_copy_templates_results + +- name: Force update and restart container + community.docker.docker_compose: + project_src: watchtower + state: present + pull: true + restarted: "{{ watchtower_copy_templates_results.changed }}" + become: true diff --git a/roles/watchtower/tasks/main.yml b/roles/watchtower/tasks/main.yml new file mode 100644 index 0000000..3f670ac --- /dev/null +++ b/roles/watchtower/tasks/main.yml @@ -0,0 +1,4 @@ +--- + +- ansible.builtin.import_tasks: base.yml + name: base \ No newline at end of file diff --git a/roles/watchtower/templates/docker-compose.yml.j2 b/roles/watchtower/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..f15dfd3 --- /dev/null +++ b/roles/watchtower/templates/docker-compose.yml.j2 @@ -0,0 +1,9 @@ +version: '3' + +services: + watchtower: + image: containrrr/watchtower:latest + restart: always + container_name: watchtower + volumes: + - /var/run/docker.sock:/var/run/docker.sock