mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-15 11:32:05 +00:00
71 lines
2.7 KiB
YAML
71 lines
2.7 KiB
YAML
---
|
|
# Copyright (c) Ansible Project
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
- name: Get OS version
|
|
ansible.builtin.command: uname -r
|
|
register: os_version
|
|
|
|
- name: Install pre-reqs
|
|
ansible.builtin.apt:
|
|
name: '{{ docker_prereq_packages }}'
|
|
state: present
|
|
update_cache: true
|
|
notify: cleanup docker
|
|
|
|
- when:
|
|
- (ansible_facts.distribution == "Ubuntu" and (ansible_facts.distribution_major_version | int) >= 22) or
|
|
(ansible_facts.distribution == "Debian" and (ansible_facts.distribution_major_version | int) >= 12)
|
|
name: Add Docker repo on Ubuntu 22+ or Debian 12+
|
|
block:
|
|
- name: Add gpg key
|
|
ansible.builtin.get_url:
|
|
url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg"
|
|
dest: /etc/apt/keyrings/docker.asc
|
|
|
|
- name: Add Docker repo
|
|
ansible.builtin.apt_repository:
|
|
repo: deb [arch={{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable
|
|
state: present
|
|
|
|
- when:
|
|
- (ansible_facts.distribution == "Ubuntu" and (ansible_facts.distribution_major_version | int) < 22) or
|
|
(ansible_facts.distribution == "Debian" and (ansible_facts.distribution_major_version | int) < 12)
|
|
name: Add Docker repo on Ubuntu 20 or before, or Debian 11 or before
|
|
block:
|
|
- name: Add gpg key
|
|
ansible.builtin.shell: curl -fsSL https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg >key && apt-key add key # noqa: command-instead-of-module
|
|
|
|
- name: Add Docker repo
|
|
ansible.builtin.apt_repository:
|
|
repo: deb [arch={{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable
|
|
state: present
|
|
|
|
- block:
|
|
- name: Prevent service restart
|
|
ansible.builtin.copy:
|
|
content: exit 101
|
|
dest: /usr/sbin/policy-rc.d
|
|
backup: true
|
|
mode: '0755'
|
|
register: policy_rc_d
|
|
|
|
- name: Install Docker CE
|
|
ansible.builtin.apt:
|
|
name: '{{ docker_packages if needs_docker_daemon else docker_cli_packages }}'
|
|
state: present
|
|
|
|
always:
|
|
- name: Restore /usr/sbin/policy-rc.d (if needed)
|
|
ansible.builtin.command: mv {{ policy_rc_d.backup_file }} /usr/sbin/policy-rc.d
|
|
when:
|
|
- '"backup_file" in policy_rc_d'
|
|
|
|
- name: Remove /usr/sbin/policy-rc.d (if needed)
|
|
ansible.builtin.file:
|
|
path: /usr/sbin/policy-rc.d
|
|
state: absent
|
|
when:
|
|
- '"backup_file" not in policy_rc_d'
|