Initial commit

This commit is contained in:
2024-02-25 01:16:42 +03:00
commit 30a9e6599d
12 changed files with 211 additions and 0 deletions

31
tasks/composes.yml Normal file
View File

@@ -0,0 +1,31 @@
---
- name: create dir for ymls
file:
path: "{{ dst_compose_files_dir }}"
state: directory
mode: '0755'
- name: Save all env variables to a file
ansible.builtin.shell:
cmd: printenv > {{ dst_compose_files_dir }}/.env
args:
executable: /bin/bash
- name: create compose file
copy:
src: "{{ 'files/' + (inventory_hostname if molecule_file is not defined else 'molecule') + '/docker-compose.yml' }}"
dest: "{{ dst_compose_files_dir }}/docker-compose.yml"
mode: '0644'
- name: deploy compose file
docker_compose:
env_file: "{{ dst_compose_files_dir }}/.env"
project_src: "{{ dst_compose_files_dir }}"
files: ["{{ dst_compose_files_dir }}/{{ item.name }}.yml"]
state: "{{ item.state | default('present') }}"
remove_orphans: "{{ item.remove_orphans | default('yes') }}"
recreate: "{{ item.recreate | default('smart') }}"
pull: "{{ item.pull | default('yes') }}"
stopped: "{{ item.stopped | default('no') }}"
timeout: "{{ item.timeout | default('10') }}"
debug: "{{ item.debug | default('no') }}"

20
tasks/config.yml Normal file
View File

@@ -0,0 +1,20 @@
---
- name: create directories
file:
path: "{{ item }}"
state: directory
mode: '0755'
with_items:
- /etc/systemd/system/docker.service.d
- /etc/docker
- name: create daemon.json
template:
src: daemon-json.j2
dest: /etc/docker/daemon.json
mode: 0640
register: docker_daemon_json
notify:
- restart docker service
- meta: flush_handlers

52
tasks/install.yml Normal file
View File

@@ -0,0 +1,52 @@
---
- name: Update apt cache
apt:
update_cache: yes
- name: Install utils
retries: 3
delay: 5
ansible.builtin.apt:
pkg:
- ca-certificates
- curl
- gpg
update_cache: yes
cache_valid_time: 3600
- name: Make sure the APT keyring directory exists
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
- name: Register the Docker GPG key with APT
become: true
ansible.builtin.apt_key:
url: "{{ repo_key }}"
state: present
- name: Add Docker repository to APT sources
apt_repository:
repo: "{{ repo_url }}"
state: present
filename: docker
- name: create user for remap
user:
name: "{{ remap_user }}"
comment: "User for docker userns-remap"
state: present
create_home: false
when: remap_enable
- name: Install Docker-CE
retries: 3
delay: 5
ansible.builtin.apt:
pkg:
- docker-ce
update_cache: yes
cache_valid_time: 3600
- meta: flush_handlers

15
tasks/main.yml Normal file
View File

@@ -0,0 +1,15 @@
---
- name: docker installation
include_tasks: install.yml
- name: docker configuration
include_tasks: config.yml
- name: Check for docker-compose.yml in the specific directory
ansible.builtin.stat:
path: "{{ 'files/' + (inventory_hostname if molecule_file is not defined else 'molecule') + '/docker-compose.yml' }}"
register: docker_compose_stat
- name: deploy compose files
include_tasks: composes.yml
when: docker_compose_stat.stat.exists