From 4ab2a471b955e2d60617fb00667f3edcd8950345 Mon Sep 17 00:00:00 2001 From: theadam Date: Mon, 28 Oct 2024 15:08:20 +0100 Subject: [PATCH] + README + fixed fact gathering --- tasks/README.md | 18 ++++++++++++++++++ tasks/install_debian.yaml | 6 ++---- tasks/main.yaml | 6 ++++-- 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 tasks/README.md diff --git a/tasks/README.md b/tasks/README.md new file mode 100644 index 0000000..ebb9aab --- /dev/null +++ b/tasks/README.md @@ -0,0 +1,18 @@ +# install-docker-ce + +## Purpose of this role + +With this role it is possible to install Docker CE and Docker Compose Plugin from Docker repo with custom options and add users to Docker group to access the daemon. + +### ENV variables + +The following environmental variables can be used in your playbook vars: + +- docker_users: [] array that contains users who can access Docker via the socket and Docker CLI command +- docker_daemon_options: {} dict, that can contains the settings of `/etc/docker/daemon.json` +> Note: As the daemon config file set up first, the network IP addresses can be set properly after the first installation. + +### todo + +- Add the ability to login to user-defined creds to registries +- Support other distributions than Debian \ No newline at end of file diff --git a/tasks/install_debian.yaml b/tasks/install_debian.yaml index 519d08d..a22358c 100644 --- a/tasks/install_debian.yaml +++ b/tasks/install_debian.yaml @@ -1,4 +1,3 @@ ---- - name: Install dependencies ansible.builtin.apt: update_cache: true @@ -7,14 +6,13 @@ - ca-certificates state: present -- name: Add Docker apt key. +- name: Add Docker apt key ansible.builtin.get_url: url: "{{ docker_apt_gpg_key }}" dest: "/etc/apt/keyrings/docker.asc" mode: "0644" -- name: Add Docker repository. - gather_facts: true +- name: Add Docker repository ansible.builtin.apt_repository: repo: "{{ docker_apt_repository }}" state: present diff --git a/tasks/main.yaml b/tasks/main.yaml index b52ab33..93ed2c0 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -1,5 +1,4 @@ --- - - name: /etc/docker/ directory exists ansible.builtin.file: path: /etc/docker @@ -12,9 +11,12 @@ dest: /etc/docker/daemon.json mode: "0644" +- name: Gather facts within role + ansible.builtin.setup: + - name: Install Docker if Debian ansible.builtin.import_tasks: "install_debian.yaml" - when: ansible_facts.ansible_distribution | lower == "debian" + when: ansible_distribution | lower == "debian" - name: Add user(s) to Docker group ansible.builtin.user: