diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2de2499 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "ansible.python.interpreterPath": "/opt/local/bin/python3.10" +} \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml index e8dc435..378cf51 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,7 @@ --- docker_install: true +docker_specific_package_ver: false +docker_pkg_version: "5:24.0.1" # Swarm docker_swarm: false docker_swarm_manager: false diff --git a/meta/main.yml b/meta/main.yml index 1f7da5f..82e534b 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,13 +1,12 @@ galaxy_info: author: Andrea Dell'Amico - description: Systems Architect + namespace: adellam + role_name: docker + description: Role that installs Docker from their repository company: ISTI-CNR - - issue_tracker_url: https://redmine-s2i2s.isti.cnr.it/projects/provisioning - license: EUPL 1.2+ - min_ansible_version: 2.8 + min_ansible_version: "2.9" # To view available platforms and versions (or releases), visit: # https://galaxy.ansible.com/api/v1/platforms/ @@ -16,13 +15,12 @@ galaxy_info: - name: Ubuntu versions: - bionic - - name: EL - versions: - - 7 - - 8 + - focal + - jammy galaxy_tags: - - users + - docker + - containers dependencies: - src: git+https://gitea-s2i2s.isti.cnr.it/ISTI-ansible-roles/ansible-role-python3-environment.git diff --git a/tasks/deb_pkgs.yml b/tasks/deb_pkgs.yml index bf1f72e..6411eca 100644 --- a/tasks/deb_pkgs.yml +++ b/tasks/deb_pkgs.yml @@ -1,37 +1,67 @@ --- -- block: +- name: Docker.com repository + when: docker_install | bool + tags: [docker,docker_pkg] + block: - name: Add the Docker repository key - #apt_key: keyserver={{ docker_repo_keyserver }} id={{ docker_repo_key }} state=present - apt_key: url={{ docker_deb_repo_key_url }} state=present + ansible.builtin.apt_key: + url: "{{ docker_deb_repo_key_url }}" + state: present - name: Remove the old docker packages, from the old distribution method - apt: pkg={{ docker_deb_old_packages }} state=absent + ansible.builtin.apt: + pkg: "{{ docker_deb_old_packages }}" + state: absent - name: Remove the obsolete docker repository - apt_repository: repo='{{ docker_deb_repo_old }}' state=absent update_cache=yes + ansible.builtin.apt_repository: + repo: "{{ docker_deb_repo_old }}" + state: absent + update_cache: true - name: Add the Docker repository - apt_repository: repo='{{ docker_deb_repo }}' update_cache=yes + ansible.builtin.apt_repository: + repo: "{{ docker_deb_repo }}" + update_cache: true - - name: Install Docker - apt: pkg={{ docker_deb_packages }} state={{ docker_pkg_status }} update_cache=yes cache_valid_time=3600 + - name: Install the latest Docker package available + ansible.builtin.apt: + pkg: "{{ docker_deb_packages }}" + state: "{{ docker_pkg_status }}" + cache_valid_time: 3600 + when: not docker_specific_package_ver - when: docker_install | bool - tags: docker + - name: Install a specific Docker package version + ansible.builtin.apt: + pkg: "{{ docker_versioned_deb_packages }}" + state: "{{ docker_pkg_status }}" + cache_valid_time: 3600 + force: true + when: docker_specific_package_ver -- block: +- name: Remove the docker packages and repository + when: not docker_install | bool + tags: [docker,docker_pkg] + block: - name: Ensure that the service is stopped and disabled - service: name=docker state=stopped enabled=no - ignore_errors: True + ansible.builtin.service: + name: docker + state: stopped + enabled: false + ignore_errors: true - name: Remove the Docker package - apt: pkg={{ docker_deb_packages }} state=absent + ansible.builtin.apt: + pkg: "{{ docker_deb_packages }}" + state: absent - name: Remove the Docker repository key - apt_key: id={{ docker_deb_repo_key }} state=absent + ansible.builtin.apt_key: + id: "{{ docker_deb_repo_key }}" + state: absent - name: Remove the Docker repository - apt_repository: repo='{{ docker_deb_repo }}' state=absent update_cache=yes - - when: not docker_install | bool - tags: docker + ansible.builtin.apt_repository: + repo: "{{ docker_deb_repo }}" + state: absent + update_cache: true diff --git a/vars/main.yml b/vars/main.yml index 4677d43..e74a077 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -17,8 +17,15 @@ docker_pkg_status: present docker_deb_packages: - docker-ce - docker-ce-cli + - docker-ce-rootless-extras - containerd.io +docker_versioned_deb_packages: + - "docker-ce={{ docker_pkg_version }}" + - "docker-ce-cli{{ docker_pkg_version }}" + - "docker-ce-rootless-extras{{ docker_pkg_version }}" + - containerd.io + docker_deb_old_packages: - docker-engine - docker.io