diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 444586d..9e68165 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -133,24 +133,14 @@ - name: Verify Docker compose plugin is installed become: true become_user: "{{ docker_user }}" + environment: + PATH: "{{ docker_user_info.home }}/bin:{{ docker_user_info.home }}/.local/bin:{{ ansible_env.PATH }}" ansible.builtin.command: cmd: docker compose version register: docker_compose_plugin changed_when: false failed_when: docker_compose_plugin.rc != 0 - when: docker_rootful and docker_compose - - - name: Verify that docker-compose is installed - become: true - become_user: "{{ docker_user }}" - environment: - PATH: "{{ docker_user_info.home }}/bin:{{ docker_user_info.home }}/.local/bin" - ansible.builtin.command: - cmd: docker-compose version - register: docker_compose_version - changed_when: false - failed_when: docker_compose_version.rc != 0 - when: not docker_rootful and docker_compose + when: docker_compose - name: Container verification block environment: diff --git a/tasks/docker_compose.yml b/tasks/docker_compose.yml new file mode 100644 index 0000000..4671daa --- /dev/null +++ b/tasks/docker_compose.yml @@ -0,0 +1,54 @@ +--- +- name: Install Docker compose + become: true + ansible.builtin.package: + name: docker-compose-plugin + state: present + when: docker_rootful + tags: + - apt + - dnf + - docker-compose + +- name: Install rootless Docker compose + when: not docker_rootful + become: true + become_user: "{{ docker_user }}" + tags: + - docker-compose + block: + - name: Stat Compose in /bin dir + ansible.builtin.stat: + path: "{{ docker_user_info.home }}/bin/docker-compose" + register: docker_compose_bin + + - name: Debug + ansible.builtin.debug: + msg: "{{ docker_compose_bin }}" + + - name: Create cli-plugins directory + ansible.builtin.file: + path: "{{ docker_user_info.home }}/.docker/cli-plugins" + state: directory + mode: "0700" + + - name: Download docker-compose + ansible.builtin.get_url: + url: "https://github.com/docker/compose/releases/download/v{{ docker_compose_release }}/docker-compose-linux-x86_64" + dest: "{{ docker_user_info.home }}/.docker/cli-plugins/docker-compose" + checksum: sha256:{{ docker_compose_release_shasum }} + owner: "{{ docker_user }}" + mode: "0755" + when: docker_compose + + - name: Remove Compose in /bin dir + ansible.builtin.file: + path: "{{ docker_user_info.home }}/bin/docker-compose" + state: absent + when: docker_compose_bin.stat.exists and not docker_compose_bin.stat.islnk + + - name: Create Compose link + ansible.builtin.file: + src: "{{ docker_user_info.home }}/.docker/cli-plugins/docker-compose" + dest: "{{ docker_user_info.home }}/bin/docker-compose" + state: link diff --git a/tasks/docker_install_rootful.yml b/tasks/docker_install_rootful.yml index bafde61..c0db0a3 100644 --- a/tasks/docker_install_rootful.yml +++ b/tasks/docker_install_rootful.yml @@ -62,14 +62,3 @@ - apt - dnf - docker - -- name: Install Docker compose - become: true - ansible.builtin.package: - name: docker-compose-plugin - state: present - when: docker_compose - tags: - - apt - - dnf - - docker-compose diff --git a/tasks/docker_install_rootless.yml b/tasks/docker_install_rootless.yml index ad8e220..1efe2f3 100644 --- a/tasks/docker_install_rootless.yml +++ b/tasks/docker_install_rootless.yml @@ -76,19 +76,6 @@ - --strip-components=1 remote_src: true -- name: Download docker-compose - become: true - become_user: "{{ docker_user }}" - ansible.builtin.get_url: - url: "https://github.com/docker/compose/releases/download/v{{ docker_compose_release }}/docker-compose-linux-x86_64" - dest: "{{ docker_user_info.home }}/bin/docker-compose" - checksum: sha256:{{ docker_compose_release_shasum }} - owner: "{{ docker_user }}" - mode: "0755" - when: docker_compose - tags: - - docker-compose - - name: Add Docker systemd service become: true become_user: "{{ docker_user }}" diff --git a/tasks/docker_service_rootful.yml b/tasks/docker_service_rootful.yml index d78b4dc..c6c3f4d 100644 --- a/tasks/docker_service_rootful.yml +++ b/tasks/docker_service_rootful.yml @@ -50,7 +50,7 @@ tags: - modprobe -- name: Install rootless docker +- name: Install rootless Docker become: true become_user: "{{ docker_user }}" environment: diff --git a/tasks/main.yml b/tasks/main.yml index 3da4105..193b9de 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -28,10 +28,14 @@ msg: slirp4netns (>= 0.4.0) is required, currently not available in Debian <= 10 when: docker_rootful and (ansible_distribution == "Debian" and ansible_distribution_major_version <= '10') -- name: Install and configure rootless docker +- name: Install and configure rootless Docker ansible.builtin.include_tasks: docker_install_rootless.yml when: not docker_rootful +- name: Install Docker Compose + ansible.builtin.include_tasks: docker_compose.yml + when: docker_compose + - name: Add user sudo alias vars: sudo_alias: >