This commit is contained in:
Francesco Spilla 2022-10-24 14:47:10 +02:00
commit af35fdeb48
9 changed files with 144 additions and 0 deletions

39
README.md Normal file
View File

@ -0,0 +1,39 @@
Ansible Role: Docker host
=========================
This roles installs and configures the latest version of docker and docker-compose from the official Docker CE repository.
Requirements
------------
None.
Role Variables
--------------
Available variables are listed below, along with default values (see `defaults/main.yml`):
docker_compose_version: "v2.4.1"
The version of docker-compose to install.
docker_user_username: "root"
The username that will run docker (specify a user to run docker deamon in rootless mode).
Dependencies
------------
None.
Example Playbook
----------------
- hosts: servers
roles:
- { role: docker-host }
License
-------
MIT / BSD

4
defaults/main.yml Normal file
View File

@ -0,0 +1,4 @@
---
# defaults file for docker-host
docker_compose_version: "v2.4.1"
docker_user_username: "root"

2
handlers/main.yml Normal file
View File

@ -0,0 +1,2 @@
---
# handlers file for docker-host

15
meta/main.yml Normal file
View File

@ -0,0 +1,15 @@
galaxy_info:
author: f.spilla
description: Opinionated docker and docker-compose installation for Ubuntu.
issue_tracker_url: https://git-repo.eu/f.spilla/ansible-docker-host-role/issues
license: MIT
min_ansible_version: 2.9
platforms:
- name: Ubuntu
versions:
- focal
- jammy
galaxy_tags: []
dependencies: []

43
tasks/main.yml Normal file
View File

@ -0,0 +1,43 @@
---
# tasks file for docker-host
# OS-specific tasks
- include_tasks: setup-Ubuntu.yml
when: ansible_distribution == 'Ubuntu'
# Setup tasks
- name: Install docker module for python
become: true
pip:
name: docker
- name: Install docker compose
become: true
get_url:
url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-linux-x86_64
dest: /usr/local/bin/docker-compose
mode: 755
- name: Create docker group (for root-less docker)
become: true
group:
name: docker
state: present
- name: Add user to the docker group (for root-less docker)
become: true
user:
name: "{{ docker_user_username }}"
groups: docker
append: true
- name: Install docker-compose module for python
become: true
pip:
name: docker-compose
- name: Create base docker folder for apps
file:
path: ~/docker
state: directory
become_user: "{{ docker_user_username }}"

32
tasks/setup-Ubuntu.yml Normal file
View File

@ -0,0 +1,32 @@
---
- name: Install docker prerequisites
become: true
apt:
name:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
- vim
- haveged
- python3-pip
- name: Add docker GPG apt key
become: true
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add docker PPA for Ubuntu {{ ansible_distribution_release }}
become: true
apt_repository:
repo: deb https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable
state: present
- name: Update apt and install docker-ce
become: true
apt:
name: docker-ce
state: latest
update_cache: true

2
tests/inventory Normal file
View File

@ -0,0 +1,2 @@
localhost

5
tests/test.yml Normal file
View File

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- docker-host

2
vars/main.yml Normal file
View File

@ -0,0 +1,2 @@
---
# vars file for docker-host