2019-10-27 15:25:33 +00:00
|
|
|
---
|
|
|
|
# Server/Borgbackup: Install and Setup Borgbackup Backup Crobjob - Default Debian Version
|
|
|
|
# Variables:
|
|
|
|
# - dockercompose_use_pip: boolean to use pip instead of manual download (default: false)
|
|
|
|
|
|
|
|
# Detect some more host facts
|
|
|
|
- name: docker - Detect architecture
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.shell: dpkg --print-architecture
|
2019-10-27 15:25:33 +00:00
|
|
|
register: dpkg_arch
|
|
|
|
|
|
|
|
# Install docker CE
|
|
|
|
- name: docker - Install docker CE APT dependencies
|
|
|
|
become: yes
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.apt:
|
2019-10-27 15:25:33 +00:00
|
|
|
name: "{{ packages }}"
|
|
|
|
state: present
|
|
|
|
vars:
|
|
|
|
packages:
|
2019-11-11 17:15:33 +00:00
|
|
|
- apt-transport-https
|
|
|
|
- ca-certificates
|
|
|
|
- curl
|
|
|
|
- gnupg2
|
|
|
|
- software-properties-common
|
2019-10-27 15:25:33 +00:00
|
|
|
- name: docker - Add docker CE repo key
|
|
|
|
become: yes
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.apt_key:
|
2019-10-27 15:25:33 +00:00
|
|
|
url: https://download.docker.com/linux/debian/gpg
|
|
|
|
state: present
|
|
|
|
|
|
|
|
# IMPORTANT: raspbian needs deb [arch=armhf] https://download.docker.com/linux/raspbian ...
|
|
|
|
- name: docker - Add docker CE repo (Debian)
|
|
|
|
become: yes
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.apt_repository:
|
2019-10-27 15:25:33 +00:00
|
|
|
repo: "deb [arch={{ dpkg_arch.stdout }}] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
|
|
|
|
state: present
|
2020-04-18 22:24:00 +00:00
|
|
|
when: ansible_facts['lsb']['id'] != "Raspbian"
|
2020-05-24 15:08:11 +00:00
|
|
|
- name: docker - Add docker CE repo (Raspbian)
|
2019-10-27 15:25:33 +00:00
|
|
|
become: yes
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.apt_repository:
|
2019-10-27 15:25:33 +00:00
|
|
|
repo: "deb [arch={{ dpkg_arch.stdout }}] https://download.docker.com/linux/raspbian {{ ansible_distribution_release }} stable"
|
|
|
|
state: present
|
2020-04-18 22:24:00 +00:00
|
|
|
when: ansible_facts['lsb']['id'] == "Raspbian"
|
2019-10-27 15:25:33 +00:00
|
|
|
|
|
|
|
- name: docker - Install docker CE
|
|
|
|
become: yes
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.apt:
|
2019-10-27 15:25:33 +00:00
|
|
|
name: docker-ce
|
|
|
|
state: latest
|
2020-04-19 13:13:21 +00:00
|
|
|
install_recommends: no
|
2019-10-27 15:25:33 +00:00
|
|
|
update_cache: yes
|
2020-04-17 10:15:14 +00:00
|
|
|
cache_valid_time: "3600"
|
2019-10-27 15:25:33 +00:00
|
|
|
|
2019-11-02 17:47:57 +00:00
|
|
|
# Install latest release of docker-compose (using pip3)
|
|
|
|
# docker only provides pre-compiled binaries for x86_64, but not for armhf/ arm64!
|
|
|
|
# but ansible needs the python package anyway
|
2020-04-17 10:15:14 +00:00
|
|
|
- name: docker-compose - Discover if ARM is used
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.set_fact:
|
2019-10-27 15:25:33 +00:00
|
|
|
dockercompose_use_pip: true
|
2020-04-19 18:19:20 +00:00
|
|
|
when: ansible_architecture == "aarch64" or ansible_architecture == "armv7l"
|
2019-10-27 15:25:33 +00:00
|
|
|
|
|
|
|
- name: docker-compose - Install x86_46 binary
|
|
|
|
block:
|
|
|
|
- name: docker-compose - Get version number of stable
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.shell: |
|
2019-10-27 15:25:33 +00:00
|
|
|
curl -s https://api.github.com/repos/docker/compose/releases/latest \
|
|
|
|
| grep tag_name \
|
|
|
|
| cut -d '"' -f 4
|
|
|
|
args:
|
|
|
|
warn: false
|
|
|
|
register: latest_dc_version
|
|
|
|
- name: docker-compose - Download and install
|
|
|
|
become: yes
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.get_url:
|
2019-10-27 15:25:33 +00:00
|
|
|
url: "https://github.com/docker/compose/releases/download/{{ latest_dc_version.stdout }}/docker-compose-Linux-x86_64"
|
|
|
|
dest: /usr/local/bin/docker-compose
|
|
|
|
force: yes # otherwise updates will not be downloaded
|
|
|
|
- name: docker-compose - Make docker-compose executable
|
|
|
|
become: yes
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.file:
|
2019-10-27 15:25:33 +00:00
|
|
|
path: /usr/local/bin/docker-compose
|
|
|
|
mode: 0755
|
2020-04-19 18:19:20 +00:00
|
|
|
when: dockercompose_use_pip == false and ansible_architecture == "x86_64"
|
2019-11-02 17:47:57 +00:00
|
|
|
- name: docker-compose - Install python package
|
2019-10-27 15:25:33 +00:00
|
|
|
block:
|
|
|
|
- name: docker-compose - Install requirements
|
|
|
|
become: yes
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.apt:
|
2019-11-11 17:15:33 +00:00
|
|
|
name: "{{ packages }}"
|
2019-10-27 15:25:33 +00:00
|
|
|
state: present
|
2019-11-11 17:15:33 +00:00
|
|
|
vars:
|
|
|
|
packages:
|
|
|
|
- python3-pip
|
|
|
|
- python3-setuptools
|
2019-10-27 15:25:33 +00:00
|
|
|
- name: docker-compose - Install using pip3
|
|
|
|
become: yes
|
2021-08-28 14:50:37 +00:00
|
|
|
ansible.builtin.pip:
|
2019-10-27 15:25:33 +00:00
|
|
|
name: docker-compose
|
|
|
|
executable: pip3
|
2020-04-19 18:19:20 +00:00
|
|
|
when: dockercompose_use_pip == true
|