matrix-docker-compose/ansible/roles/docker-compose/tasks/main.yml
2024-02-20 20:17:05 +09:00

114 lines
2.7 KiB
YAML

- name: Remove docker if installed from CentOS repo
yum:
name:
- docker
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine
state: absent
- name: Install required pkgs
yum:
name:
- yum-utils
- device-mapper-persistent-data
- lvm2
state: latest
- name: Add Docker repo
get_url:
url: https://download.docker.com/linux/centos/docker-ce.repo
dest: /etc/yum.repos.d/docker-ce.repo
- name: Install Docker
yum:
name:
- docker-ce
- docker-ce-cli
- containerd.io
state: latest
- name: Start Docker service
service:
name: docker
state: started
enabled: yes
tags:
- service
- docker
- name: Check if /usr/local/bin/docker-compose exists.
stat:
path: /usr/local/bin/docker-compose
register: docker_compose_file
- name: Check current docker-compose version
shell:
cmd: /usr/local/bin/docker-compose --version | cut -d ' ' -f3 | sed 's/.$//'
register: docker_compose_vsn
changed_when: false
failed_when: false
args:
warn: no
when:
- docker_compose_file.stat.exists
- set_fact:
docker_compose_current_version: "{{ docker_compose_vsn.stdout }}"
when:
- docker_compose_vsn.stdout is defined and docker_compose_file.stat.exists
- name: Install or upgrade docker-compose
get_url:
url : "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64"
dest: /usr/local/bin/docker-compose
mode: 'a+x'
force: yes
when: >
docker_compose_current_version is not defined
or docker_compose_current_version is version(docker_compose_latest, '<')
- name: Add our user to docker group
ansible.builtin.user:
name: "{{ ansible_user }}"
groups: docker
append: yes
tags:
- usergroup
- name: Create docker-compose base directory
ansible.builtin.file:
path: /home/{{ ansible_user }}/docker_compose
state: directory
mode: '0755'
tags:
- dir
- name: Create docker-compose project directories
ansible.builtin.file:
path: /home/{{ ansible_user }}/docker_compose/{{ matrix_service }}
state: directory
mode: '0755'
tags:
- dir
- name: Create ~/.docker
ansible.builtin.file:
path: /home/{{ ansible_user }}/.docker
state: directory
mode: '0700'
tags:
- dir
- dot-docker
- name: Copy docker config
ansible.builtin.copy:
src: files/dot-docker/config.json
dest: /home/{{ ansible_user }}/.docker/config.json
owner: "{{ ansible_user }}"
mode: '0644'
loop: "{{ docker_compose }}"
tags:
- files
- dot-docker