From 3105ea9be1ad4b03617eee696508153006d51a1b Mon Sep 17 00:00:00 2001 From: ace Date: Thu, 23 Mar 2023 21:05:38 +0300 Subject: [PATCH] rewrite and add Debian os family support --- defaults/main.yaml | 2 +- tasks/Debian.yaml | 36 ++++++++++++++++++++++++++++++++++++ tasks/RedHat.yaml | 36 ++++++++++++++++++------------------ tasks/main.yaml | 20 +++++++++++++++++++- vars/Debian-11.yaml | 25 +++++++++++++++++++++++++ vars/RedHat.yaml | 15 +++++++++++++++ vars/Ubuntu-20.04.yaml | 25 +++++++++++++++++++++++++ vars/Ubuntu-22.04.yaml | 25 +++++++++++++++++++++++++ 8 files changed, 164 insertions(+), 20 deletions(-) create mode 100644 tasks/Debian.yaml create mode 100644 vars/Debian-11.yaml create mode 100644 vars/RedHat.yaml create mode 100644 vars/Ubuntu-20.04.yaml create mode 100644 vars/Ubuntu-22.04.yaml diff --git a/defaults/main.yaml b/defaults/main.yaml index d860b9d..aa976aa 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -1,2 +1,2 @@ --- -docker_version: "20.10.9-3.el{{ansible_facts['distribution_major_version']}}" +docker_version: "20.10.23" diff --git a/tasks/Debian.yaml b/tasks/Debian.yaml new file mode 100644 index 0000000..5e5de22 --- /dev/null +++ b/tasks/Debian.yaml @@ -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 diff --git a/tasks/RedHat.yaml b/tasks/RedHat.yaml index 48ad13b..f92ab00 100644 --- a/tasks/RedHat.yaml +++ b/tasks/RedHat.yaml @@ -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' diff --git a/tasks/main.yaml b/tasks/main.yaml index aa059e5..94a32ae 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -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" diff --git a/vars/Debian-11.yaml b/vars/Debian-11.yaml new file mode 100644 index 0000000..db779d8 --- /dev/null +++ b/vars/Debian-11.yaml @@ -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" diff --git a/vars/RedHat.yaml b/vars/RedHat.yaml new file mode 100644 index 0000000..8a788c3 --- /dev/null +++ b/vars/RedHat.yaml @@ -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" diff --git a/vars/Ubuntu-20.04.yaml b/vars/Ubuntu-20.04.yaml new file mode 100644 index 0000000..60b906e --- /dev/null +++ b/vars/Ubuntu-20.04.yaml @@ -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" diff --git a/vars/Ubuntu-22.04.yaml b/vars/Ubuntu-22.04.yaml new file mode 100644 index 0000000..cc20a98 --- /dev/null +++ b/vars/Ubuntu-22.04.yaml @@ -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"