2022-05-20 01:06:34 +00:00
|
|
|
- name: Install Docker
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.apt:
|
2022-05-20 01:06:34 +00:00
|
|
|
name: ['docker.io', 'docker-compose']
|
2019-09-18 02:32:08 +00:00
|
|
|
state: present
|
|
|
|
update_cache: true
|
|
|
|
|
2022-05-27 03:50:14 +00:00
|
|
|
- name: Create docker-compose root
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.file:
|
2022-05-28 03:14:06 +00:00
|
|
|
path: "{{ docker_compose_root }}"
|
2022-05-27 03:50:14 +00:00
|
|
|
state: directory
|
2023-05-04 05:44:18 +00:00
|
|
|
mode: 0500
|
2022-05-27 03:50:14 +00:00
|
|
|
|
|
|
|
- name: Install docker-compose systemd service
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.template:
|
2022-05-27 03:50:14 +00:00
|
|
|
src: docker-compose.service.j2
|
|
|
|
dest: "/etc/systemd/system/{{ docker_compose_service }}@.service"
|
2023-05-04 05:44:18 +00:00
|
|
|
mode: 0400
|
|
|
|
notify: compose_systemd
|
2022-05-27 03:50:14 +00:00
|
|
|
|
2023-07-20 07:51:44 +00:00
|
|
|
- name: Create directories to clone docker-compose repositories
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0400
|
|
|
|
loop:
|
|
|
|
- "{{ docker_repos_path }}"
|
|
|
|
- "{{ docker_repos_keys }}"
|
|
|
|
when: docker_compose_deploy is defined
|
|
|
|
|
|
|
|
- name: Generate OpenSSH deploy keys for docker-compose clones
|
|
|
|
community.crypto.openssh_keypair:
|
|
|
|
path: "{{ docker_repos_keys }}/id_{{ docker_repos_keytype }}"
|
|
|
|
type: "{{ docker_repos_keytype }}"
|
|
|
|
mode: 0400
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Clone external docker-compose projects
|
|
|
|
ansible.builtin.git:
|
|
|
|
repo: "{{ item.url }}"
|
|
|
|
dest: "{{ docker_repos_path }}/{{ item.name }}"
|
|
|
|
version: "{{ item.version | default('main') }}"
|
|
|
|
force: true
|
|
|
|
key_file: "{{ docker_repos_keys }}/id_{{ docker_repos_keytype }}"
|
|
|
|
when: docker_compose_deploy is defined
|
|
|
|
loop: "{{ docker_compose_deploy }}"
|
|
|
|
|
|
|
|
- name: Create directories for docker-compose projects using the systemd service
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ docker_compose_root }}/{{ item.name }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0400
|
|
|
|
loop: "{{ docker_compose_deploy }}"
|
|
|
|
when: docker_compose_deploy is defined
|
|
|
|
|
|
|
|
- name: Copy docker-compose.yml files to their service directories
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: "{{ docker_repos_path }}/{{ item.name }}/{{ item.path | default('docker-compose.yml') }}"
|
|
|
|
dest: "{{ docker_compose_root }}/{{ item.name }}/docker-compose.yml"
|
|
|
|
remote_src: yes
|
|
|
|
loop: "{{ docker_compose_deploy }}"
|
|
|
|
when: docker_compose_deploy is defined
|
|
|
|
|
|
|
|
- name: Set environment variables for docker-compose projects
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: docker-compose-env.j2
|
|
|
|
dest: "{{ docker_compose_root }}/{{ item.name }}/.env"
|
|
|
|
mode: 0400
|
|
|
|
loop: "{{ docker_compose_deploy }}"
|
|
|
|
when: docker_compose_deploy is defined and item.env is defined
|
|
|
|
|
2020-09-03 01:21:14 +00:00
|
|
|
- name: Add users to docker group
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.user:
|
2020-09-03 01:21:14 +00:00
|
|
|
name: "{{ item }}"
|
2019-09-18 02:32:08 +00:00
|
|
|
groups: docker
|
2020-08-01 00:52:57 +00:00
|
|
|
append: true
|
2020-09-03 01:21:14 +00:00
|
|
|
loop: "{{ docker_users }}"
|
2020-11-22 05:46:08 +00:00
|
|
|
when: docker_users is defined
|
2019-09-18 02:32:08 +00:00
|
|
|
|
2020-08-01 00:52:57 +00:00
|
|
|
- name: Start Docker and enable on boot
|
2023-05-04 03:42:55 +00:00
|
|
|
ansible.builtin.service:
|
2020-08-01 00:52:57 +00:00
|
|
|
name: docker
|
|
|
|
state: started
|
|
|
|
enabled: true
|
2023-07-20 07:51:44 +00:00
|
|
|
|
|
|
|
- name: Start docker-compose services and enable on boot
|
|
|
|
ansible.builtin.service:
|
|
|
|
name: "{{ docker_compose_service }}@{{ item.name }}"
|
|
|
|
state: started
|
|
|
|
enabled: true
|
|
|
|
loop: "{{ docker_compose_deploy }}"
|
|
|
|
when: item.enabled is defined and item.enabled is true
|