From 060434541c82db3b374774a59695803e710b198f Mon Sep 17 00:00:00 2001 From: Josh Lay Date: Wed, 30 Aug 2023 20:43:46 -0500 Subject: [PATCH] docker: simplify, use dist-based vars --- roles/docker/defaults/main.yml | 4 ++++ roles/docker/tasks/main.yml | 35 ++++++++-------------------------- 2 files changed, 12 insertions(+), 27 deletions(-) create mode 100644 roles/docker/defaults/main.yml diff --git a/roles/docker/defaults/main.yml b/roles/docker/defaults/main.yml new file mode 100644 index 000000000..85f041a --- /dev/null +++ b/roles/docker/defaults/main.yml @@ -0,0 +1,4 @@ +--- +docker_pkgs: + Ubuntu: docker.io + Fedora: moby-engine diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index 0e6da6b..cf8559a 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -1,32 +1,13 @@ --- +# depends on create-user role / create_username var -- name: install docker - package: - name: docker - state: latest - when: ansible_distribution in ["CentOS", "Fedora", "Red Hat Enterprise Linux", "RedHat"] and not is_atomic - register: docker_installed +- name: "Install Docker" + ansible.builtin.package: + name: "{{ docker_pkgs[ansible_distribution] }}" + state: present -- name: add {{ username }} to 'dockerroot' group - user: - name: "{{ username }}" - groups: dockerroot - append: yes - when: ansible_distribution in ["CentOS", "Red Hat Enterprise Linux", "RedHat"] and not is_atomic - - -- name: copy daemon.json - copy: - src: roles/docker/files/daemon.json - dest: /etc/docker/daemon.json - owner: root - group: root - mode: 0644 - when: ansible_distribution in ["CentOS", "Red Hat Enterprise Linux", "RedHat"] and not is_atomic - -- name: enable/start docker - service: +- name: Enable/start docker + ansible.builtin.service: name: docker state: started - enabled: yes - when: ansible_distribution in ["CentOS", "Fedora", "Red Hat Enterprise Linux", "RedHat"] and not is_atomic + enabled: true