library/roles/docker: Update the docker role.

This commit is contained in:
Andrea Dell'Amico 2016-12-05 19:26:29 +01:00
parent 1703ebc746
commit 3849810903
3 changed files with 44 additions and 12 deletions

13
docker/defaults/main.yml Normal file
View File

@ -0,0 +1,13 @@
---
docker_install: False
docker_swarm: False
docker_repo_key: '58118E89F3A912897C070ADBF76221572C52609D'
docker_repo_keyserver: 'hkp://ha.pool.sks-keyservers.net:80'
# Set to the Debian distribution name if not Ubuntu
docker_distribution: '{{ ansible_distribution_release | lower }}'
docker_repo: 'deb https://apt.dockerproject.org/repo {{ ansible_distribution }}-{{ docker_distribution }} main'
docker_pkg_status: latest
docker_packages:
- docker-engine

View File

@ -4,4 +4,5 @@
- name: Enable Docker TCP on local bridge (for docker swarm)
action: configfile path=/etc/default/docker syntax=shell key=DOCKER_OPTS value="\"-H tcp://172.17.42.1:2375 -H unix:///var/run/docker.sock\""
notify: Restart docker
when: docker_swarm
tags: docker-conf

View File

@ -1,16 +1,34 @@
---
- name: Add Docker repository key
apt_key: url="https://get.docker.io/gpg"
tags:
- docker
- block:
- name: Add the Docker repository key
apt_key: keyserver={{ docker_repo_keyserver }} id=docker_repo_key state=present
- name: Add Docker repository
apt_repository: repo='deb http://get.docker.io/ubuntu docker main' update_cache=yes
tags:
- docker
- name: Add the Docker repository
apt_repository: repo='{{ docker_repo }}' update_cache=yes
- name: Install Docker
apt: pkg=lxc-docker state=present
tags:
- docker
- name: Install Docker
apt: pkg={{ item }} state={{ docker_pkg_status }} update_cache=yes cache_valid_time=3600
with_items: '{{ docker_packages }}'
- name: Ensure that the service is started and enabled
service: name=docker state=started enabled=yes
when: docker_install
tags: docker
- block:
- name: Ensure that the service is stopped and disabled
service: name=docker state=stopped enabled=no
- name: Remove the Docker package
apt: pkg={{ item }} state=absent
with_items: '{{ docker_packages }}'
- name: Remove the Docker repository key
apt_key: keyserver={{ docker_repo_keyserver }} id=docker_repo_key state=absent
- name: Remove the Docker repository
apt_repository: repo='{{ docker_repo }}' state=absent update_cache=yes
when: not docker_install
tags: docker