diff --git a/defaults/main.yml b/defaults/main.yml index 9c86b81..d18af49 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,7 +2,7 @@ # defaults file for install_docker install_docker_edition: ce # can be ce or ee (community or enterprise) install_docker_start_service: true -install_docker_compose: false +install_docker_compose: true install_docker_compose_version: latest install_docker_python_packages: true install_docker_python_packages_version: latest diff --git a/tasks/install.yml b/tasks/install.yml index a578475..60ee53c 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,5 +1,13 @@ --- # task/install file for install_docker +- name: "Configure docker repository" + ansible.builtin.include_role: + name: ednxzu.manage_repositories + vars: + manage_repositories_enable_default_repo: false + manage_repositories_enable_custom_repo: true + manage_repositories_custom_repo: "{{ install_docker_repository }}" + - name: "Install docker packages" ansible.builtin.include_role: name: ednxzu.manage_apt_packages diff --git a/tasks/install_compose.yml b/tasks/install_compose.yml new file mode 100644 index 0000000..53c7e7b --- /dev/null +++ b/tasks/install_compose.yml @@ -0,0 +1,46 @@ +--- +# task/install_compose file for install_docker +- name: "Get release for compose:{{ install_docker_compose_version }}" + vars: + _docker_compose_url_ext: "{% if install_docker_compose_version == 'latest'%}releases{% else %}releases/tags{% endif %}" + ansible.builtin.uri: + url: "{{ install_docker_compose_github_api }}/{{ _docker_compose_url_ext }}/{{ install_docker_compose_version }}" + return_content: true + register: _docker_compose_new_release + +- name: "Check current compose version" + command: "{{ install_docker_compose_path }} --version" + register: _docker_compose_old_release + check_mode: false + changed_when: false + failed_when: false + +- name: "Set facts for wanted compose release" + ansible.builtin.set_fact: + install_docker_compose_wanted_version: "{{ _docker_compose_new_release.json['tag_name']|regex_replace('v', '') }}" + when: _docker_compose_new_release.json is defined + and (_docker_compose_new_release.json | length > 0) + +- name: "Set facts for current compose release" + ansible.builtin.set_fact: + install_docker_compose_current_version: "{{ _docker_compose_old_release.stdout | regex_search('(\\d+(\\.\\d+)+)') }}" + when: _docker_compose_old_release.stdout is defined + and (_docker_compose_old_release.stdout | length > 0) + +- name: "Remove old compose binary if different" + ansible.builtin.file: + path: "{{ install_docker_compose_path }}" + state: absent + register: _docker_compose_binary_removed + when: install_docker_compose_current_version is defined + and install_docker_compose_wanted_version not in install_docker_compose_current_version + +- name: "Download and install compose:{{ install_docker_compose_version }}" + ansible.builtin.get_url: + url: "{{ install_docker_compose_github_url }}/releases/download/v{{ install_docker_compose_wanted_version }}/docker-compose-linux-{{ ansible_architecture }}" + dest: "{{ install_docker_compose_path }}" + owner: root + group: root + mode: '0755' + when: (install_docker_compose_current_version is not defined) + or (_docker_compose_binary_removed.changed) diff --git a/tasks/main.yml b/tasks/main.yml index 88c14bf..170d8e3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,10 +1,14 @@ --- # task/main file for install_docker -- name: "Import prerequisites.yml" - ansible.builtin.include_tasks: prerequisites.yml +- name: "Import install_compose.yml" + ansible.builtin.include_tasks: install_compose.yml + when: install_docker_compose -- name: "Import install.yml" - ansible.builtin.include_tasks: install.yml - -- name: "Import configure.yml" - ansible.builtin.include_tasks: configure.yml \ No newline at end of file +# - name: "Import prerequisites.yml" +# ansible.builtin.include_tasks: prerequisites.yml +# +# - name: "Import install.yml" +# ansible.builtin.include_tasks: install.yml +# +# - name: "Import configure.yml" +# ansible.builtin.include_tasks: configure.yml \ No newline at end of file diff --git a/tasks/prerequisites.yml b/tasks/prerequisites.yml index 8bc845d..4a525cb 100644 --- a/tasks/prerequisites.yml +++ b/tasks/prerequisites.yml @@ -1,9 +1,2 @@ --- # task/prerequisites file for install_docker -- name: "Configure docker repository" - ansible.builtin.include_role: - name: ednxzu.manage_repositories - vars: - manage_repositories_enable_default_repo: false - manage_repositories_enable_custom_repo: true - manage_repositories_custom_repo: "{{ install_docker_repository }}" \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml index 14585f5..b54ea54 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,5 +1,8 @@ --- # vars file for install_docker +install_docker_compose_path: "/usr/local/bin/docker-compose" +install_docker_compose_github_api: https://api.github.com/repos/docker/compose +install_docker_compose_github_url: https://github.com/docker/compose install_docker_packages: - name: "docker-{{ install_docker_edition }}" version: latest @@ -13,12 +16,10 @@ install_docker_packages: - name: "containerd.io" version: latest state: present - install_docker_compose_packages: - name: version: state: "{{ 'present' if install_docker_compose else 'absent' }}" - install_docker_repository: - uri: "https://download.docker.com/linux/{{ ansible_distribution|lower }}" gpg_key: "https://download.docker.com/linux/{{ ansible_distribution|lower }}/gpg"