matrix-docker-compose/ansible/roles/docker-compose/tasks/main.yml

105 lines
2.5 KiB
YAML
Raw Normal View History

2023-09-19 10:48:24 +00:00
- 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/{{ item }}
state: directory
mode: '0755'
loop: "{{ docker_compose }}"
tags:
- dir
- name: Copy docker-compose contents
ansible.builtin.copy:
src: files/{{ item }}/
dest: /home/{{ ansible_user }}/docker_compose/{{ item }}
owner: "{{ ansible_user }}"
2023-09-27 10:26:37 +00:00
mode: '0644'
loop: "{{ docker_compose }}"
tags:
- files