added install for docker-compose, supports 'latest' as a version

This commit is contained in:
Bertrand Lanson 2023-04-06 23:42:29 +02:00
parent f0b868b84a
commit f1de8adce3
6 changed files with 69 additions and 17 deletions

View File

@ -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

View File

@ -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

46
tasks/install_compose.yml Normal file
View File

@ -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)

View File

@ -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
# - 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

View File

@ -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 }}"

View File

@ -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"