diff --git a/defaults/main.yml b/defaults/main.yml index c0252ba..674af76 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -69,15 +69,14 @@ docker_ca_certificates_src_dir: "{{ '~/docker-ca-certificates' | expanduser }}" # certificate files (besides other locations). docker_ca_certificates_dst_dir: "/usr/local/share/ca-certificates" -# Currently only "standalone" is supported. So that means on the remote host -# "docker-compose" command will be available and not the "docker compose" -# plugin (without "-"). -# When commented no "docker-compose" will be installed and all "docker_compose_*" -# variables are ignored. -# docker_compose_type: "standalone" +# 2 kind of compose installation are supported (standalone to support legacy environments): +# - standalone: The standalone "docker-compose" binary. This is the old way to use "docker-compose". The binary is called "docker-compose" and is installed in a directory defined by `docker_compose_bin_directory` variable. This is the default value for `docker_compose_type` variable. +# - plugin: The "docker compose" plugin for "docker" CLI. This is the new way to use "docker-compose". The binary is called "docker-compose" and is installed in "/usr/local/lib/docker/cli-plugins/docker-compose". This is the recommended way to use "docker-compose" and is the default value for `docker_compose_type` variable. +# When commented no "docker-compose" will be installed and all "docker_compose_*" variables will be ignored. +docker_compose_type: "standalone" # "docker-compose" version -docker_compose_version: "2.38.2" +docker_compose_version: "5.1.1" # The directory where to "docker-compose" binary will be installed docker_compose_bin_directory: "/usr/local/bin" diff --git a/tasks/deps-debian.yml b/tasks/deps-debian.yml new file mode 100644 index 0000000..1d31815 --- /dev/null +++ b/tasks/deps-debian.yml @@ -0,0 +1,5 @@ +--- +- name: Install prerequisite packages + ansible.builtin.apt: + name: "{{ dependency_packages }}" + state: present \ No newline at end of file diff --git a/tasks/deps-redhat.yml b/tasks/deps-redhat.yml new file mode 100644 index 0000000..e897bfe --- /dev/null +++ b/tasks/deps-redhat.yml @@ -0,0 +1,4 @@ +- name: Install prerequisite packages + ansible.builtin.package: + name: "{{ dependency_packages }}" + state: present \ No newline at end of file diff --git a/tasks/docker-compose-plugin.yml b/tasks/docker-compose-plugin.yml new file mode 100644 index 0000000..bdf7eda --- /dev/null +++ b/tasks/docker-compose-plugin.yml @@ -0,0 +1,18 @@ +--- + +- name: Ensure docker compose cli plugins directory exists + ansible.builtin.file: + path: /usr/local/lib/docker/cli-plugins + state: directory + owner: root + group: root + mode: "0755" + +- name: Downloading docker compose plugins binary v2 and make exec + ansible.builtin.get_url: + url: "https://github.com/docker/compose/releases/download/v{{ docker_compose_version }}/docker-compose-{{ ansible_system | lower }}-{{ ansible_architecture }}" + dest: "/usr/local/lib/docker/cli-plugins/docker-compose" + mode: "{{ docker_compose_bin_file_perm }}" + owner: "{{ docker_compose_bin_owner }}" + group: "{{ docker_compose_bin_group }}" + checksum: "sha256:https://github.com/docker/compose/releases/download/v{{ docker_compose_version }}/docker-compose-{{ ansible_system | lower }}-{{ ansible_architecture }}.sha256" \ No newline at end of file diff --git a/tasks/docker-compose.yml b/tasks/docker-compose-standalone.yml similarity index 100% rename from tasks/docker-compose.yml rename to tasks/docker-compose-standalone.yml diff --git a/tasks/main.yml b/tasks/main.yml index 83bbe54..1a6d9cc 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -16,19 +16,8 @@ tags: - always -- name: Bootstrap python3-apt on Debian family hosts - when: - - ansible_facts['os_family'] == "Debian" - ansible.builtin.raw: | - if python3 -c 'import apt' >/dev/null 2>&1; then - echo "python3-apt already present" - else - export DEBIAN_FRONTEND=noninteractive - apt-get update - apt-get install -y python3-apt - fi - register: docker__python3_apt_bootstrap - changed_when: "'python3-apt already present' not in docker__python3_apt_bootstrap.stdout" +- ansible.builtin.include_tasks: deps-{{ ansible_os_family | lower }}.yml + when: ansible_os_family in ['RedHat', 'Debian'] # supported os family - name: Gather the package facts ansible.builtin.package_facts: @@ -241,9 +230,9 @@ - name: Install docker-compose binary when: - - docker_compose_type is defined + - docker_compose_type is defined and docker_compose_type in ['standalone', 'plugin'] ansible.builtin.include_tasks: - file: "tasks/docker-compose.yml" + file: "tasks/docker-compose-{{ docker_compose_type }}.yml" apply: tags: - docker-compose diff --git a/vars/debian-11.yml b/vars/debian-11.yml index c0aa297..e0aa8b0 100644 --- a/vars/debian-11.yml +++ b/vars/debian-11.yml @@ -1,3 +1,5 @@ --- docker_ip_nft_tables_packages: iptables: "iptables" +dependency_packages: + - python3-apt \ No newline at end of file diff --git a/vars/debian-12.yml b/vars/debian-12.yml index c0aa297..e0aa8b0 100644 --- a/vars/debian-12.yml +++ b/vars/debian-12.yml @@ -1,3 +1,5 @@ --- docker_ip_nft_tables_packages: iptables: "iptables" +dependency_packages: + - python3-apt \ No newline at end of file diff --git a/vars/debian.yml b/vars/debian.yml index c0aa297..e0aa8b0 100644 --- a/vars/debian.yml +++ b/vars/debian.yml @@ -1,3 +1,5 @@ --- docker_ip_nft_tables_packages: iptables: "iptables" +dependency_packages: + - python3-apt \ No newline at end of file diff --git a/vars/ubuntu-22.yml b/vars/ubuntu-22.yml index c0aa297..e0aa8b0 100644 --- a/vars/ubuntu-22.yml +++ b/vars/ubuntu-22.yml @@ -1,3 +1,5 @@ --- docker_ip_nft_tables_packages: iptables: "iptables" +dependency_packages: + - python3-apt \ No newline at end of file diff --git a/vars/ubuntu-24.yml b/vars/ubuntu-24.yml index c0aa297..e0aa8b0 100644 --- a/vars/ubuntu-24.yml +++ b/vars/ubuntu-24.yml @@ -1,3 +1,5 @@ --- docker_ip_nft_tables_packages: iptables: "iptables" +dependency_packages: + - python3-apt \ No newline at end of file diff --git a/vars/ubuntu.yml b/vars/ubuntu.yml index c0aa297..e0aa8b0 100644 --- a/vars/ubuntu.yml +++ b/vars/ubuntu.yml @@ -1,3 +1,5 @@ --- docker_ip_nft_tables_packages: iptables: "iptables" +dependency_packages: + - python3-apt \ No newline at end of file