mirror of
https://github.com/KevinMidboe/playbooks-retailor.git
synced 2026-09-07 13:32:06 +00:00
update docker role & add separate play
This commit is contained in:
@@ -1,27 +1,22 @@
|
||||
---
|
||||
- name: Check if the current distro is supported (Ubuntu or Debian)
|
||||
set_fact:
|
||||
distro_supported: "{{ ansible_facts['distribution'].lower() in supported_distros }}"
|
||||
tags:
|
||||
- check_distro
|
||||
- name: Determine if the current distro is supported
|
||||
ansible.builtin.set_fact:
|
||||
docker_distro_supported: "{{ ansible_facts['distribution'] | lower in docker_supported_distros }}"
|
||||
|
||||
- name: Set installation URL based on the distro
|
||||
set_fact:
|
||||
install_url: "https://download.docker.com/linux/{{ ansible_facts['distribution'].lower() }} {{ ansible_distribution_release }} stable"
|
||||
when: distro_supported
|
||||
tags:
|
||||
- set_url
|
||||
|
||||
- name: Log Unsupported Distro
|
||||
debug:
|
||||
msg: "The {{ ansible_facts['distribution'] }} distribution is not supported. Skipping Docker installation."
|
||||
when: not distro_supported
|
||||
tags:
|
||||
- unsupported_distro
|
||||
|
||||
- name: Skip Docker installation task if distro is unsupported
|
||||
meta: end_play
|
||||
when: not distro_supported
|
||||
tags:
|
||||
- end_play
|
||||
- name: Fail on unsupported distro
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
{{ ansible_facts['distribution'] }} is not a supported distribution for
|
||||
the docker role. Supported: {{ docker_supported_distros | join(', ') }}.
|
||||
when:
|
||||
- not docker_distro_supported
|
||||
- docker_fail_on_unsupported_distro
|
||||
|
||||
- name: Notify unsupported distro is being skipped
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
{{ ansible_facts['distribution'] }} is not supported by the docker role.
|
||||
Skipping Docker installation on this host.
|
||||
when:
|
||||
- not docker_distro_supported
|
||||
- not docker_fail_on_unsupported_distro
|
||||
|
||||
@@ -1,12 +1,49 @@
|
||||
---
|
||||
- name: Add Docker repository
|
||||
apt_repository:
|
||||
repo: deb {{ install_url }}
|
||||
state: present
|
||||
when: distro_supported
|
||||
- name: Remove conflicting/legacy Docker packages
|
||||
ansible.builtin.package:
|
||||
name: "{{ docker_clean_install_remove_packages }}"
|
||||
state: absent
|
||||
|
||||
- name: Install Docker
|
||||
apt:
|
||||
name: "{{ docker_package }}"
|
||||
- name: Install prerequisite packages
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- ca-certificates
|
||||
- curl
|
||||
- gnupg
|
||||
state: present
|
||||
when: distro_supported
|
||||
update_cache: true
|
||||
|
||||
- name: Ensure apt keyrings directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ docker_apt_keyring_dir }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: Download Docker's official GPG key
|
||||
ansible.builtin.get_url:
|
||||
url: "{{ docker_apt_repo_url }}/{{ ansible_facts['distribution'] | lower }}/gpg"
|
||||
dest: "{{ docker_apt_keyring_file }}"
|
||||
mode: "0644"
|
||||
force: true
|
||||
|
||||
- name: Add Docker apt repository
|
||||
ansible.builtin.apt_repository:
|
||||
repo: >-
|
||||
deb [arch={{ 'amd64' if ansible_facts['architecture'] == 'x86_64' else ansible_facts['architecture'] }}
|
||||
signed-by={{ docker_apt_keyring_file }}]
|
||||
{{ docker_apt_repo_url }}/{{ ansible_facts['distribution'] | lower }}
|
||||
{{ ansible_facts['distribution_release'] }} stable
|
||||
state: present
|
||||
filename: docker
|
||||
update_cache: false
|
||||
|
||||
- name: Update apt cache
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
cache_valid_time: "{{ docker_apt_cache_valid_time }}"
|
||||
|
||||
- name: Install Docker packages
|
||||
ansible.builtin.package:
|
||||
name: "{{ docker_install_packages }}"
|
||||
state: present
|
||||
notify: Restart Docker
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
---
|
||||
- name: Include distro check tasks
|
||||
include_tasks: check_distro.yml
|
||||
tags:
|
||||
- check_distro
|
||||
|
||||
- name: Include Docker installation tasks if distro is supported
|
||||
include_tasks: install.yml
|
||||
when: distro_supported
|
||||
tags:
|
||||
- install
|
||||
+19
-41
@@ -1,45 +1,23 @@
|
||||
---
|
||||
- name: Clean install by removing any docker package
|
||||
package: name={{ item }} state=absent
|
||||
with_items: "{{ clean_install_remove_packages }}"
|
||||
- name: Assert supported distribution
|
||||
ansible.builtin.include_tasks: check_distro.yml
|
||||
tags:
|
||||
- docker_check_distro
|
||||
|
||||
- name: Ensure curl & ca-certs are installed
|
||||
package:
|
||||
name:
|
||||
- ca-certificates
|
||||
- curl
|
||||
- gnupg
|
||||
state: latest
|
||||
- name: Install Docker
|
||||
ansible.builtin.include_tasks: install.yml
|
||||
when: docker_distro_supported
|
||||
tags:
|
||||
- docker_install
|
||||
|
||||
- name: Ensure docker keyring file exists
|
||||
file:
|
||||
path: /etc/apt/keyrings/docker.gpg
|
||||
state: touch
|
||||
|
||||
- name: Download docker gpg key and add to keyrings
|
||||
shell: |
|
||||
install -m 0755 -d /etc/apt/keyrings
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
|
||||
chmod a+r /etc/apt/keyrings/docker.gpg
|
||||
- name: Configure Docker group membership
|
||||
ansible.builtin.include_tasks: users.yml
|
||||
when: docker_distro_supported and docker_users | length > 0
|
||||
tags:
|
||||
- docker_users
|
||||
|
||||
- name: Sign and add docker deb source
|
||||
shell: |
|
||||
echo \
|
||||
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
|
||||
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
|
||||
tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
|
||||
- name: Update apt sources
|
||||
become: true
|
||||
apt:
|
||||
update_cache: yes
|
||||
cache_valid_time: 1
|
||||
|
||||
- name: Install docker packages
|
||||
package: name={{ item }} state=latest
|
||||
with_items: "{{ install_packages }}"
|
||||
|
||||
- name: Ensure group docker exists
|
||||
user:
|
||||
name: docker
|
||||
state: present
|
||||
- name: Manage Docker service
|
||||
ansible.builtin.include_tasks: service.yml
|
||||
when: docker_distro_supported
|
||||
tags:
|
||||
- docker_service
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
---
|
||||
- name: Start and enable Docker service
|
||||
systemd:
|
||||
ansible.builtin.systemd:
|
||||
name: docker
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- name: Start and enable Docker service
|
||||
systemd:
|
||||
name: docker
|
||||
enabled: yes
|
||||
state: started
|
||||
when: distro_supported
|
||||
|
||||
enabled: "{{ docker_service_enabled }}"
|
||||
state: "{{ docker_service_state }}"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
- name: Ensure docker group exists
|
||||
ansible.builtin.group:
|
||||
name: docker
|
||||
state: present
|
||||
|
||||
- name: Add users to the docker group
|
||||
ansible.builtin.user:
|
||||
name: "{{ item }}"
|
||||
groups: docker
|
||||
append: true
|
||||
loop: "{{ docker_users }}"
|
||||
Reference in New Issue
Block a user