Complete rewrite of docker installer
This commit is contained in:
@@ -1,70 +1,22 @@
|
|||||||
---
|
---
|
||||||
- name: Standardize Docker installation and ACL across hosts
|
- name: Install Docker and standardize ACL on /opt/docker
|
||||||
hosts: all
|
hosts: all
|
||||||
become: true
|
become: true
|
||||||
gather_facts: true
|
gather_facts: true
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
docker_repo_file: /etc/apt/sources.list.d/docker.list
|
|
||||||
docker_key_path: /etc/apt/keyrings/docker.gpg
|
|
||||||
docker_acl_path: /opt/docker
|
docker_acl_path: /opt/docker
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Check if Docker is already installed
|
- name: Check if Docker is already installed (by package)
|
||||||
command: docker --version
|
command: dpkg -s docker-ce
|
||||||
register: docker_installed
|
register: docker_check
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
- name: Remove legacy docker APT source if missing signed-by
|
- name: Install Docker via official script if not present
|
||||||
file:
|
shell: curl -fsSL https://get.docker.com | sh
|
||||||
path: "{{ docker_repo_file }}"
|
when: docker_check.rc != 0
|
||||||
state: absent
|
|
||||||
when: docker_installed.rc != 0 or
|
|
||||||
"signed-by=" not in (lookup("file", docker_repo_file, errors="ignore") or "")
|
|
||||||
|
|
||||||
- name: Ensure keyring directory exists
|
|
||||||
file:
|
|
||||||
path: /etc/apt/keyrings
|
|
||||||
state: directory
|
|
||||||
mode: "0755"
|
|
||||||
|
|
||||||
- name: Download Docker GPG key and convert to binary keyring
|
|
||||||
shell: |
|
|
||||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o {{ docker_key_path }}
|
|
||||||
args:
|
|
||||||
creates: "{{ docker_key_path }}"
|
|
||||||
|
|
||||||
- name: Stat Docker GPG key file
|
|
||||||
stat:
|
|
||||||
path: "{{ docker_key_path }}"
|
|
||||||
register: docker_key_stat
|
|
||||||
|
|
||||||
- name: Fail early if key file is missing or unreadable
|
|
||||||
fail:
|
|
||||||
msg: "Docker GPG key is missing or unreadable"
|
|
||||||
when: not docker_key_stat.stat.exists or docker_key_stat.stat.size == 0
|
|
||||||
|
|
||||||
- name: Add Docker APT repository (signed-by style)
|
|
||||||
apt_repository:
|
|
||||||
repo: "deb [arch=amd64 signed-by={{ docker_key_path }}] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable"
|
|
||||||
filename: docker
|
|
||||||
state: present
|
|
||||||
update_cache: false
|
|
||||||
|
|
||||||
- name: Update apt cache
|
|
||||||
apt:
|
|
||||||
update_cache: true
|
|
||||||
|
|
||||||
- name: Install Docker engine and compose plugin (if missing)
|
|
||||||
apt:
|
|
||||||
name:
|
|
||||||
- docker-ce
|
|
||||||
- docker-ce-cli
|
|
||||||
- containerd.io
|
|
||||||
- docker-buildx-plugin
|
|
||||||
- docker-compose-plugin
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Ensure docker group exists
|
- name: Ensure docker group exists
|
||||||
group:
|
group:
|
||||||
@@ -85,7 +37,7 @@
|
|||||||
group: docker
|
group: docker
|
||||||
mode: "0775"
|
mode: "0775"
|
||||||
|
|
||||||
- name: Check for existing default ACL on folder
|
- name: Check for existing default ACL on Docker folder
|
||||||
command: getfacl --access --default {{ docker_acl_path }}
|
command: getfacl --access --default {{ docker_acl_path }}
|
||||||
register: facl_check
|
register: facl_check
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|||||||
Reference in New Issue
Block a user