ansible: add docker-compose on VMs

This commit is contained in:
Nico Schottelius 2023-09-19 12:48:24 +02:00
parent d61af93d85
commit 07c73d8dfc
4 changed files with 97 additions and 5 deletions

View file

@ -1,17 +1,25 @@
runa: runa:
vars: vars:
ansible_user: nschottelius ansible_user: nschottelius
ansible_become: true
docker_compose: false
docker_compose_version: "1.29.1"
ssh_keys: ssh_keys:
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE9P5aA5O4Vsgg5sB6Ojk+z1f5F97hvwRRd3gi+a+GGq nico-2016" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIE9P5aA5O4Vsgg5sB6Ojk+z1f5F97hvwRRd3gi+a+GGq nico-2016"
- "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCjWYALKYHTs6mX7GrrpxR0TPhxwVplmmcTPAA7zjhVCZajcUwLduy3Yct4YXBwRiEydGyhExoVVB8i7UhyvMQsTheRk751uJZyKWIkqbQJoJx1LPmZ00EJNaiIEiJih762D9KWZ1GoLBfB4QAEmoWDzVm3CFJ9tBVEsQ7i9BH+Cbe2GsnqflfWjb09bZhaOSTrmWNcBxgpXirZyi8EI0SrVtmnwVzdH8HXOalvFqW57aY1q/RjE1DIh7Pp+RiGscZz6CJ5oJtSEKbjZ2aUe4gomlQwYmGNVk22RdjvB7+0KDXMwdp702Z5ETv2xYk9v5YrA/lsWk/9JX8vGYb5Y5N+GGG9woZ5M1JIRjXduxNf68VMSQbxZTeonoWkh6Q8CNgDsHyyAyNuPAss7SCCGk5G8s0q/4IDGfV0A1QKFhHOId1qEqGQtLKaRbo6ZTi9wXSieA5D3kMNh+WWufutxI/t56USzNSaeYjqpYwiICBZ8jzWBJrDamiFne4KkW3PTao7Czv6yIeXHHfGYDtdvXppMSjamw+rbA/btTes5X+pYlFxniO5sZJUa+jnJOo3SYBGoRYftqxw7Usqm/i/koHP1RM8L3Iq+/xXNr5+AyFzRBCUUuDfRw1MY1n9OJXvYykNGth4ablfVFcP1R8Qq7jVGksK1dzckzD9SmCdubzwtw== nico-2014"
children: children:
chdc1: lat:
hosts: hosts:
mtx-elem-1.lat.internal.ru.com: mtx-elem-1.lat.internal.ru.com:
docker_compose: true
# 10.165.66.57 # 10.165.66.57
mtx-elem-2.lat.internal.ru.com: mtx-elem-2.lat.internal.ru.com:
docker_compose: true
# 10.165.66.58 # 10.165.66.58
mtx-syna-1.lat.internal.ru.com: mtx-syna-1.lat.internal.ru.com:
docker_compose: true
# 10.165.66.59 # 10.165.66.59
mtx-syna-2.lat.internal.ru.com: mtx-syna-2.lat.internal.ru.com:
docker_compose: true
# 10.165.66.60 # 10.165.66.60

View file

@ -6,7 +6,9 @@
name: base name: base
tags: tags:
- base - base
# - name: Add DNS to APU - name: Add docker-compose
# include_role: include_role:
# name: apu-service-dns name: docker-compose
# when: apu_is_service_apu is defined tags:
- docker
when: docker_compose

View file

@ -5,3 +5,6 @@
state: present state: present
key: "{{ item }}" key: "{{ item }}"
with_items: "{{ ssh_keys }}" with_items: "{{ ssh_keys }}"
tags:
- base
- ssh

View file

@ -0,0 +1,79 @@
- 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: Convert old images to new runtime
# shell:
# cmd: " grep -rl 'docker-runc' /var/lib/docker/containers/ | xargs sed -i 's/docker-runc/runc/g' "
# changed_when: false
# failed_when: false
- 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, '<')