Merge pull request #35 from paulfantom/cleanup

Cleanup
master
Carlos León 7 years ago committed by GitHub
commit deb13dcf10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,12 +1,10 @@
[![Build Status](https://travis-ci.org/mongrelion/ansible-role-docker.svg?branch=master)](https://travis-ci.org/mongrelion/ansible-role-docker)
docker
=========
# docker
Install and configure Docker.
Role Variables
--------------
## Role Variables
### `docker_config`
@ -23,7 +21,7 @@ Specify the version of Docker to install, e.g. `1.12.6`, `17.05`.
Default value: `17.03`
### `setup_script_md5_sum`
### `docker_setup_script_md5_sum`
Default value: md5 checksum of default `docker_version` setup script (see `defaults/main.yml` for exact default value)
@ -34,7 +32,7 @@ Either:
1. Generate an md5 checksum for the desired version's install script
1. If you know what you are doing and are not worried about security, set this variable to "no" or "false" to disable checksum verification of the setup script.
### `setup_script_url`
### `docker_setup_script_url`
URL pointing to a Docker setup script that will install the specified `docker_version`.
@ -42,31 +40,30 @@ Default value: `https://releases.rancher.com/install-docker/{{ docker_version }}
The default URL utilizes [Rancher Labs' version-specific, OS-agnostic setup scripts](https://github.com/rancher/install-docker), which in turn just install the appropriate version of `docker-ce` or `docker-engine` from the official Docker `apt` and `yum` repositories.
### `upgrade_docker`
### `docker_upgrade`
Per default, this role will only download and run the installation script when
Docker is not installed (or more precise: when `dockerd` is not in `$PATH`). Set
`upgrade_docker` to `True` to override this behavior and force the install
`docker_upgrade` to `True` to override this behavior and force the install
script to be run.
So in order to upgrade Docker on managed systems, take the following steps:
0. Either download a newer version of this role (with a more recent default
version) or update `docker_version` and `setup_script_md5_sum` in your
version) or update `docker_version` and `docker_setup_script_md5_sum` in your
host/group vars.
1. Run your playbook with `-e upgrade_docker=True`
1. Run your playbook with `-e docker_upgrade=True`
### `docker_proxy`, `docker_http_proxy`, `docker_https_proxy`, `docker_no_proxy`
`docker_proxy` specifies if proxy need to be applied. Default value of `docker_proxy` is no. If you need proxy set it to yes and updated other three variables as needed.
Dependencies
------------
## Dependencies
None
Example Playbook
----------------
## Example Playbook
Install Docker
```yaml
- hosts: servers
@ -84,28 +81,24 @@ Install and configure docker
userland-proxy: false
```
Testing
-------
For development, we use Vagrant.
Bring the VM up with
```
$ vagrant up
```
This will automatically run the playbooks against the virtual machine once it's up.
After making changes to any playbook, you can test the provisioning with
## Testing
The preferred way of locally testing the role is to use Docker and [molecule](https://github.com/metacloud/molecule) (v1.25). You will have to install Docker on your system. See Get started for a Docker package suitable to for your system.
All packages you need to can be specified in one line:
```sh
pip install ansible 'ansible-lint>=3.4.15' 'molecule==1.25.0' docker 'testinfra>=1.7.0,<=1.10.1'
```
$ vagrant provision
This should be similar to one listed in `.travis.yml` file in `install` section.
After installing test suit you can run test by running
```sh
molecule test
```
For more information about molecule go to their [docs](http://molecule.readthedocs.io/en/stable-1.25/).
License
-------
## License
MIT
Author Information
------------------
## Author Information
You can find me on Twitter: [@mongrelion](https://twitter.com/mongrelion)

@ -1,22 +1,19 @@
---
consul_ip: 127.0.0.1
docker_clusterstore: no
dockerpy: no
vagrant: no
docker_proxy: no
docker_http_proxy: ""
docker_https_proxy: ""
docker_no_proxy: ""
upgrade_docker: false
default_docker_config:
docker_upgrade: false
docker_default_config:
storage-driver: devicemapper
log-level: info
docker_version: "17.06"
setup_script_url: "https://releases.rancher.com/install-docker/{{ docker_version }}.sh"
docker_setup_script_url: "https://releases.rancher.com/install-docker/{{ docker_version }}.sh"
# DANGER! THIS VALUE IS USED TO VERIFY THAT THE DOCKER SETUP SCRIPT IS LEGITIMATE.
# DO NOT MODIFY THIS UNLESS YOU HAVE SPECIFIED A DIFFERENT "docker_version" or "setup_script_url"
# IF YOU HAVE GENERATED AN MD5 CHECKSUM FOR YOUR DESIRED SETUP SCRIPT, STORE IT IN THIS VARIABLE
# IF YOU REALLY DON'T WANT TO VERIFY CHECKSUM, SET THIS VALUE TO "false" or "no"
setup_script_md5_sum: "6be324016277879d49bd0e7f9f91e546"
docker_setup_script_md5_sum: "6be324016277879d49bd0e7f9f91e546"

@ -1,15 +1,14 @@
---
- name: Compose md5 checksum
set_fact:
setup_script_checksum: "md5:{{ setup_script_md5_sum }}"
when: setup_script_md5_sum is defined and setup_script_md5_sum
__docker_setup_script_checksum: "md5:{{ docker_setup_script_md5_sum }}"
when: docker_setup_script_md5_sum != ""
- name: Download docker setup script for desired version
get_url:
url: "{{ setup_script_url }}"
url: "{{ docker_setup_script_url }}"
dest: "/tmp/docker-setup.sh"
checksum: "{{ setup_script_checksum|default(omit) }}"
checksum: "{{ __docker_setup_script_checksum|default(omit) }}"
mode: 0755
- name: Execute docker setup script

@ -1,6 +1,17 @@
---
- name: Gather variables for each operating system
include_vars: "{{ item }}"
with_items: "{{ ansible_os_family | lower }}.yml"
tags:
- always
- include: "os/{{ ansible_os_family }}.yml"
- include: preflight.yml
- name: ensure docker dependencies are installed
package:
name: "{{ item }}"
state: present
with_items: "{{ docker_dependencies }}"
- name: check if docker is installed
command: which dockerd
@ -9,7 +20,7 @@
ignore_errors: yes
- include: "install.yml"
when: upgrade_docker or (which_dockerd | failed)
when: docker_upgrade or (which_dockerd | failed)
- name: ensure config folder is present
file:
@ -22,15 +33,6 @@
version: 1.9.0
when: dockerpy
- name: apply default daemon config
set_fact:
docker_json: "{{ default_docker_config | combine(docker_config | default({})) }}"
- name: configure docker clusterstore
set_fact:
docker_json: '{{ docker_json | combine({"cluster-store": "consul://{{ consul_ip }}:8500"})}}'
when: docker_clusterstore
- name: create directory for proxy file
file:
path: /etc/systemd/system/docker.service.d
@ -65,8 +67,6 @@
notify:
- restart docker
- meta: flush_handlers
- name: ensure starts on system boot
systemd:
name: docker

@ -1,8 +0,0 @@
---
- name: ensure docker dependencies are installed
apt:
name: "{{ item }}"
state: present
with_items:
- apt-transport-https
- ca-certificates

@ -1,9 +0,0 @@
---
- name: ensure docker dependencies are installed
yum:
name: "{{ item }}"
state: present
with_items:
- ca-certificates
- yum-utils

@ -0,0 +1,24 @@
---
- name: Set backwards compatibility for docker_upgrade var
set_fact:
docker_upgrade: "{{ upgrade_docker }}"
when: upgrade_docker is defined
- name: Set backwards compatibility for default_config
set_fact:
docker_default_config: "{{ default_docker_config }}"
when: default_docker_config is defined
- name: Set backwards compatibility for setup_script_md5_sum
set_fact:
docker_setup_script_md5_sum: "{{ setup_script_md5_sum }}"
when: setup_script_md5_sum is defined
- name: Set backwards compatibility for setup_script_url
set_fact:
docker_setup_script_url: "{{ setup_script_url }}"
when: setup_script_url is defined
- name: apply default daemon config
set_fact:
docker_json: "{{ docker_default_config | combine(docker_config | default({})) }}"

@ -0,0 +1,3 @@
docker_dependencies:
- apt-transport-https
- ca-certificates

@ -0,0 +1,3 @@
docker_dependencies:
- ca-certificates
- yum-utils
Loading…
Cancel
Save