commit af35fdeb480b4f42d2baf774bc41599f85764cfa Author: Francesco Spilla Date: Mon Oct 24 14:47:10 2022 +0200 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..5e1837d --- /dev/null +++ b/README.md @@ -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 diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..ad104c2 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# defaults file for docker-host +docker_compose_version: "v2.4.1" +docker_user_username: "root" diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..77b4a62 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for docker-host \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..b565835 --- /dev/null +++ b/meta/main.yml @@ -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: [] + \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..0235d0e --- /dev/null +++ b/tasks/main.yml @@ -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 }}" \ No newline at end of file diff --git a/tasks/setup-Ubuntu.yml b/tasks/setup-Ubuntu.yml new file mode 100644 index 0000000..362e646 --- /dev/null +++ b/tasks/setup-Ubuntu.yml @@ -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 \ No newline at end of file diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..f020379 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - docker-host \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..a260af3 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for docker-host \ No newline at end of file