rewrite and add Debian os family support

This commit is contained in:
ace 2023-03-23 21:05:38 +03:00
parent 2139abb875
commit 3105ea9be1
Signed by: ace
GPG Key ID: 2C08973DD37A76FD
8 changed files with 164 additions and 20 deletions

View File

@ -1,2 +1,2 @@
---
docker_version: "20.10.9-3.el{{ansible_facts['distribution_major_version']}}"
docker_version: "20.10.23"

36
tasks/Debian.yaml Normal file
View File

@ -0,0 +1,36 @@
---
- name: Install deps packages
apt:
name: "{{ docker_deps_packages }}"
state: present
update_cache: yes
- name: Add gpg keys for Docker repo
ansible.builtin.apt_key:
url: "{{ item.url }}"
keyring: "{{ item.keyring }}"
loop: "{{ docker_apt_key }}"
- name: Add Docker repository
ansible.builtin.apt_repository:
repo: "{{ item.repo }}"
state: present
filename: "{{ item.filename }}"
update_cache: yes
loop: "{{ docker_apt_repository }}"
- name: Ensure {{ docker_package }} installed
apt:
name: "{{ docker_package }}"
state: present
- name: Ensure docker service enabled and started
systemd:
name: "{{ docker_unit_name }}"
enabled: yes
state: started
- name: Ensure python3-docker installed
apt:
name: python3-docker
state: present

View File

@ -1,26 +1,26 @@
---
- name: Add Docker CE Stable repo
yum_repository:
name: "docker-ce-stable"
description: "Docker CE Stable - $basearch"
file: docker-ce
baseurl: "https://download.docker.com/linux/centos/$releasever/$basearch/stable"
enabled: no
gpgcheck: yes
gpgkey: "https://download.docker.com/linux/centos/gpg"
async: yes
ansible.builtin.yum_repository:
name: "{{ item.name }}"
description: "{{ item.description }}"
file: "{{ item.file }}"
baseurl: "{{ item.baseurl }}"
gpgcheck: "{{ item.gpgcheck | default('no') }}"
enabled: "{{ item.enabled | default('yes') }}"
repo_gpgcheck: "{{ item.repo_gpgcheck | default('no') }}"
gpgkey: "{{ item.gpgkey | default('omit') }}"
async: "{{ item.async | default('yes') }}"
loop: "{{ docker_rpm_repository }}"
- name: Ensure docker version {{ docker_version }} installed
- name: Ensure {{ docker_package }} is installed
yum:
name: "docker-ce-{{ docker_version }}"
name: "{{ docker_package }}"
state: present
enablerepo: "docker-ce-stable"
- name: Ensure docker service enabled and started
systemd:
name: docker
name: "{{ docker_unit_name }}"
enabled: yes
state: started
@ -34,17 +34,17 @@
- ansible_facts['distribution_major_version'] <= '7'
- name: Add Epel repo
yum:
dnf:
name: epel-release
state: present
when:
- ansible_facts['os_family'] == 'RedHat'
- ansible_facts['distribution_major_version'] == '8'
- ansible_facts['distribution_major_version'] >= '8'
- name: Ensure python3-docker installed
yum:
dnf:
name: python3-docker
state: present
when:
- ansible_facts['os_family'] == 'RedHat'
- ansible_facts['distribution_major_version'] == '8'
- ansible_facts['distribution_major_version'] >= '8'

View File

@ -1,3 +1,21 @@
---
- name: Include docker install
- name: Make sure handlers are flushed immediately
meta: flush_handlers
- name: Load a variable file based on the OS type
include_vars: "{{ lookup('first_found', params) }}"
vars:
params:
files:
- "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_major_version'] }}.yaml"
- "{{ ansible_facts['distribution'] }}-{{ ansible_facts['distribution_version'] }}.yaml"
- "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_major_version'] }}.yaml"
- "{{ ansible_facts['os_family'] }}-{{ ansible_facts['distribution_version'] }}.yaml"
- "{{ ansible_facts['distribution'] }}.yaml"
- "{{ ansible_facts['os_family'] }}.yaml"
paths:
- "vars"
tags: docker_vars
- name: Include docker install for {{ ansible_distribution }}
include_tasks: "{{ ansible_facts['os_family'] }}.yaml"

25
vars/Debian-11.yaml Normal file
View File

@ -0,0 +1,25 @@
docker_apt_key:
- name: "docker.gpg"
url: "https://download.docker.com/linux/debian/gpg"
keyring: "/etc/apt/trusted.gpg.d/docker.gpg"
docker_apt_repository:
- repo: "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
filename: docker
docker_deps_packages:
- gnupg
- python3-docker
docker_package_name: "docker-ce"
docker_epoch_version: "5"
docker_version_build: "~3-0~debian-bullseye"
docker_package: "{{ docker_package_name }}={{ docker_epoch_version }}:{{ docker_version }}{{ docker_version_build }}"
docker_config_dir: "/etc/docker"
docker_home_dir: "/var/lib/docker"
docker_data_dir: "{{ docker_home_dir }}/{{ docker_major_version }}/{{ docker_cluster_name }}"
docker_ssl_path: "{{ docker_config_dir }}/{{ docker_major_version }}/{{ docker_cluster_name }}"
docker_package_name_regex: "{{ docker_package_name }}-{{ docker_version }}-{{ docker_version_build }}"
docker_cluster_name: "main"
docker_ssl_update_ca_command: "update-ca-certificates --fresh"
docker_ssl_ca_trust_dir: "/usr/local/share/ca-certificates"
docker_unit_name: "docker"

15
vars/RedHat.yaml Normal file
View File

@ -0,0 +1,15 @@
docker_rpm_repository:
- name: "docker-ce-stable"
file: "docker-ce"
description: "Docker CE Stable - $basearch"
baseurl: "https://download.docker.com/linux/centos/$releasever/$basearch/stable"
repo_gpgcheck: no
gpgcheck: yes
gpgkey: "https://download.docker.com/linux/centos/gpg"
async: yes
docker_package_name: "docker-ce"
docker_package_epoch: "3"
docker_version_build: "3"
docker_package: "{{ docker_package_epoch }}:{{ docker_package_name }}-{{ docker_version }}-{{ docker_version_build }}.el{{ansible_facts['distribution_major_version']}}"
docker_unit_name: "docker"

25
vars/Ubuntu-20.04.yaml Normal file
View File

@ -0,0 +1,25 @@
docker_apt_key:
- name: "docker.gpg"
url: "https://download.docker.com/linux/ubuntu/gpg"
keyring: "/etc/apt/trusted.gpg.d/docker.gpg"
docker_apt_repository:
- repo: "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
filename: docker
docker_deps_packages:
- gnupg
- python3-docker
docker_package_name: "docker-ce"
docker_epoch_version: "5"
docker_version_build: "~3-0~ubuntu-focal"
docker_package: "{{ docker_package_name }}={{ docker_epoch_version }}:{{ docker_version }}{{ docker_version_build }}"
docker_config_dir: "/etc/docker"
docker_home_dir: "/var/lib/docker"
docker_data_dir: "{{ docker_home_dir }}/{{ docker_major_version }}/{{ docker_cluster_name }}"
docker_ssl_path: "{{ docker_config_dir }}/{{ docker_major_version }}/{{ docker_cluster_name }}"
docker_package_name_regex: "{{ docker_package_name }}-{{ docker_version }}-{{ docker_version_build }}"
docker_cluster_name: "main"
docker_ssl_update_ca_command: "update-ca-certificates --fresh"
docker_ssl_ca_trust_dir: "/usr/local/share/ca-certificates"
docker_unit_name: "docker"

25
vars/Ubuntu-22.04.yaml Normal file
View File

@ -0,0 +1,25 @@
docker_apt_key:
- name: "docker.gpg"
url: "https://download.docker.com/linux/ubuntu/gpg"
keyring: "/etc/apt/trusted.gpg.d/docker.gpg"
docker_apt_repository:
- repo: "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
filename: docker
docker_deps_packages:
- gnupg
- python3-docker
docker_package_name: "docker-ce"
docker_epoch_version: "5"
docker_version_build: "~3-0~ubuntu-jammy"
docker_package: "{{ docker_package_name }}={{ docker_epoch_version }}:{{ docker_version }}{{ docker_version_build }}"
docker_config_dir: "/etc/docker"
docker_home_dir: "/var/lib/docker"
docker_data_dir: "{{ docker_home_dir }}/{{ docker_major_version }}/{{ docker_cluster_name }}"
docker_ssl_path: "{{ docker_config_dir }}/{{ docker_major_version }}/{{ docker_cluster_name }}"
docker_package_name_regex: "{{ docker_package_name }}-{{ docker_version }}-{{ docker_version_build }}"
docker_cluster_name: "main"
docker_ssl_update_ca_command: "update-ca-certificates --fresh"
docker_ssl_ca_trust_dir: "/usr/local/share/ca-certificates"
docker_unit_name: "docker"