Skip to content

Commit

Permalink
1.1.1 (#9)
Browse files Browse the repository at this point in the history
* renamed tasks and cleaned up vars (#7)
* python lib version selection added. Resolves #6 (#8)
  • Loading branch information
Bob Killen authored Feb 1, 2017
1 parent a5e5e84 commit 51eab69
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 111 deletions.
1 change: 0 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ provisioner:
sudo_command: sudo -E -H
require_ansible_repo: false
require_ansible_omnibus: true
require_ansible_source: true
require_chef_for_busser: false
require_ruby_for_busser: false
ansible_verbose: true
Expand Down
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
AllCops:
TargetRubyVersion: 2.3

Metrics/LineLength:
Max: 99
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
1.1.1:
- Resolve Python Docker Library issue
- Rename tasks to be more clear

1.1.0:
- Add overlay2 storage driver support for Ubuntu 16.04
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This role manages the install and configuration of the Docker Engine with suppor
* [Dependencies](#dependencies)
* [Role Variables](#role-variables)
* [Execution Control](#execution-control)
* [Docker-py](#docker-py)
* [Docker Python Library](#docker-python-library)
* [Docker Engine Repository](#docker-engine-repository)
* [Docker Engine Storage Configuration](#docker-engine-storage-configuration)
* [Docker Engine](#docker-engine)
Expand All @@ -29,15 +29,13 @@ This role manages the install and configuration of the Docker Engine with suppor

Requirements
------------
This role depends on Ansible 2.1 or greater for full functionality.
If using the role to manage Docker Networks version 2.2 or higher is required and the network section in `tasks/main.yml` should be uncommented. It will become uncommented by default once Ansible 2.2 becomes more ubiquitous.

This role depends on Ansible 2.2 or greater for full functionality.


Dependencies
------------

The python library `docker-py` is a requirement for any components of the role outside of installing the Docker-Engine itself. However the role will take care of installing it, if so configured.
The python library `docker` or `docker-py` is a requirement for any components of the role outside of installing the Docker-Engine itself. However the role will take care of installing the correct version, if so configured.



Expand All @@ -52,29 +50,29 @@ Enables or disables specific components of the Docker Role.
|:------------------------------------:|:-------:|:--------------------------------------------------------------------------------------------------------------------------------------------:|
| `external_dependency_delay` | `20` | The time in seconds between external dependency retries. (repos, keyservers, etc) |
| `external_dependency_retries` | `6` | The number of retries to attempt accessing an external dependency. |
| `docker_manage_py` | `true` | Installs docker-py, either from repo or pip. **Note:** This is required for container, credential, image and network management. |
| `docker_manage_py` | `true` | Installs python docker library, either from repo or pip. **Note:** This is required for container, credential, image and network management. |
| `docker_manage_engine_repo` | `true` | Manages the Docker repo. Provides support for both the Open Source and Commercially Supported Repositories. |
| `docker_manage_engine_storage` | `false` | If true, the storage driver for the Docker Engine will be managed by the role. No storage-driver or storage-opt should be supplied manually. |
| `docker_manage_engine_users` | `true` | Creates and manages a docker group that is granted rights to interact with Docker. |
| `docker_manage_registry_credentials` | `true` | Manages the credentials for a supplied list of registries. **Note:** Requires docker-py. |
| `docker_manage_engine_networks` | `true` | Enables Management of Docker Container Networks. **Note:** Requires docker-py. |
| `docker_manage_images` | `true` | Manages lifecycle of Container Images. **Note:** Requires docker-py. |
| `docker_manage_containers` | `true` | Enables Management of Docker Container Execution. **Note:** Requires docker-py. |
| `docker_manage_registry_credentials` | `true` | Manages the credentials for a supplied list of registries. **Note:** Requires docker lib. |
| `docker_manage_engine_networks` | `true` | Enables Management of Docker Container Networks. **Note:** Requires docker lib. |
| `docker_manage_images` | `true` | Manages lifecycle of Container Images. **Note:** Requires docker lib. |
| `docker_manage_containers` | `true` | Enables Management of Docker Container Execution. **Note:** Requires docker lib. |

----------



### Docker-py
### Docker Python Library

Manages the installation of the docker-py libraries.
Manages the installation of the Python Docker library. if a version is supplied that is `2.0.0` or greater, the older `docker-py` package will be removed and the newer `docker` package installed in it's place.

| Variable | Default | Options | Description |
|:--------------------------:|:-------:|:-----------------:|:------------------------------------------------------------------------------:|
| `docker_py_install` | `pip` | `pip` or `pkg` | Type of installation. Either from pip or package. |
| `docker_py_pip_extra_args` | - | - | Extra arguments to pass to pip during execution. e.g. `-i <local pypi mirror>` |
| `docker_py_pip_upgrade` | `true` | `true` or `false` | Allow for pip to be upgraded during the install process. |
| `docker_py_version` | - | - | The version of the docker-py library to install. Defaults to latest. |
| `docker_py_version` | - | - | The version of the docker library to install. Defaults to latest. |

----------

Expand Down Expand Up @@ -143,7 +141,7 @@ Manages the Docker Engine storage driver, and in certain circumstances the stora
| `docker_engine_storage_driver` | `devicemapper` | - |
| `device` | - | **REQUIRED** The device or partition (e.g. `/dev/sdb`) intended to be used and managed by Docker. |
| `vg_name` | `docker-vg` | The name of the Docker Volume Group. |
| `vg_opts` | - | Optional paramenters to use during Volume Group creation. |
| `vg_opts` | - | Optional parameters to use during Volume Group creation. |
| `lv_name` | `thinpool` | The Logical Volume thinpool name. |
| `lv_data_opts` | `--wipesignatures y` | Parameters to pass during creation of the data logical volume. |
| `lv_metadata_opts` | `--wipesignatures y` | Parameters to pass during creation of the metadata logical volume. |
Expand Down
18 changes: 13 additions & 5 deletions spec/py_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true

# rubocop:disable Metrics/BlockLength
require 'spec_helper'

def py_pkgs
return property['_docker_py_pkg']['debian'] if %w(debian ubuntu).include?(os[:family])
return property['_docker_py_pkg']['redhat'] if %w(redhat).include?(os[:family])
end

def py_lib_name
return 'docker-py' if property['docker_py_version'] &&
property['docker_py_version'].split('.')[0].to_i < 2
'docker'
end

if property['docker_manage_py']
RSpec.describe ENV['KITCHEN_INSTANCE'] || host_inventory['hostname'] do
context 'DOCKER:PY' do
case property['docker_py_install']
when 'pkg'
context 'DOCKER:PY:PKG' do
describe 'system docker-py package' do
describe 'system python docker library' do
subject { package(py_pkgs) }
it { is_expected.to be_installed }
end
Expand All @@ -34,8 +40,8 @@ def py_pkgs
end

if property['docker_py_version']
describe 'The docker-py package version' do
subject { command('pip list | grep docker-py') }
describe 'The docker library version' do
subject { command("pip list | grep #{py_lib_name}") }
its(:stdout) { is_expected.to match property['docker_py_version'] }
end
end
Expand All @@ -46,11 +52,13 @@ def py_pkgs
verify_command =
'python -c "import sys, pkgutil; ' \
'sys.exit(0) if pkgutil.find_loader(\'docker\') else sys.exit(1)"'
describe 'docker-py library should be loadable' do
describe 'docker library should be loadable' do
subject { command(verify_command) }
its(:exit_status) { is_expected.to eq 0 }
end
end
end
end
end

# rubocop:enable Metrics/BlockLength
2 changes: 1 addition & 1 deletion tasks/container_execution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# execution covers a very broad spectrum. Images should be pulled through
# container_images before running in this section.

- name: Manage Container Exeuction
- name: EXEC - Manage Container Exeuction
docker_container:
api_version: '{{ item.api_version|default(omit) }}'
blkio_weight: '{{ item.blkio_weight|default(omit) }}'
Expand Down
2 changes: 1 addition & 1 deletion tasks/container_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# External dependency management IS done here as this is mostly used
# for pulling and not building images.

- name: Manage Container Images
- name: IMAGES - Manage Container Images
docker_image:
api_version: '{{ item.api_version|default(omit) }}'
archive_path: '{{ item.archive_path|default(omit) }}'
Expand Down
2 changes: 1 addition & 1 deletion tasks/container_networks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---

- name: Manage Container Networks
- name: NETWORKS - Manage Container Networks
docker_network:
api_version: '{{ item.api_version|default(omit) }}'
appends: '{{ item.appends|default(omit) }}'
Expand Down
16 changes: 8 additions & 8 deletions tasks/engine/debian/engine_install.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---

- name: Install Docker Engine
- name: INSTALL - ENGINE - Install Docker Engine
package: name='docker-engine={{ docker_engine_version }}*' state=present
register: _external_dependency_success
until: _external_dependency_success|success
retries: '{{ external_dependency_retries }}'
delay: '{{ external_dependency_delay }}'
when: (docker_engine_version is defined) and (docker_engine_version is not none)

- name: Install Latest Docker Engine
- name: INSTALL - ENGINE - Install Latest Docker Engine
package: name='docker-engine' state=latest
register: _external_dependency_success
until: _external_dependency_success|success
Expand All @@ -18,7 +18,7 @@

# Upstart (Ubuntu 14.04)

- name: Create Docker Upstart Defaults
- name: INSTALL - ENGINE - Create Docker Upstart Defaults
template:
src: templates/engine/upstart-defaults.j2
dest: /etc/default/docker
Expand All @@ -30,11 +30,11 @@

# Systemd (Debian Jessie, Ubuntu 16.04)

- name: Create Docker Systemd DropIn Directory
- name: INSTALL - ENGINE - Create Docker Systemd DropIn Directory
file: name='/etc/systemd/system/docker.service.d' state=directory recurse=yes
when: ansible_service_mgr == "systemd"

- name: Create Docker Systemd DropIn
- name: INSTALL - ENGINE - Create Docker Systemd DropIn
template:
src: templates/engine/systemd-config.j2
dest: /etc/systemd/system/docker.service.d/docker-opts.conf
Expand All @@ -44,16 +44,16 @@
register: _docker_engine_systemd_cfg
when: ansible_service_mgr == 'systemd'

- name: Execute Systemd Daemon-Reload
- name: INSTALL - ENGINE - Execute Systemd Daemon-Reload
command: systemctl daemon-reload
when: _docker_engine_systemd_cfg.changed

- name: Start Docker Engine Service
- name: INSTALL - ENGINE - Start Docker Engine Service
service: name=docker enabled=true state=started
register: _docker_engine_svc
when: (_docker_engine_upstart_cfg.changed) or (_docker_engine_systemd_cfg.changed)

- name: Restart Docker Engine Service
- name: INSTALL - ENGINE - Restart Docker Engine Service
service: name=docker enabled=true state=restarted sleep=5
when: (_docker_engine_upstart_cfg.changed or _docker_engine_systemd_cfg.changed) and
(not _docker_engine_svc.changed)
16 changes: 8 additions & 8 deletions tasks/engine/debian/repo.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
---

- name: Test if apt-transport-https is installed
- name: INSTALL - REPO - Test if apt-transport-https is installed
command: dpkg-query -l apt-transport-https
register: prereq_ath
changed_when: prereq_ath.rc != 0
ignore_errors: True

- name: Test if ca-certificates is installed
- name: INSTALL - REPO - Test if ca-certificates is installed
command: dpkg-query -l ca-certificates
register: prereq_cc
changed_when: prereq_cc.rc != 0
ignore_errors: True

- name: Update Apt Cache
- name: INSTALL - REPO - Update Apt Cache
apt: update_cache=yes
register: _external_dependency_success
until: _external_dependency_success|success
retries: '{{ external_dependency_retries }}'
delay: '{{ external_dependency_delay }}'
when: (prereq_ath.rc != 0) or (prereq_cc.rc != 0)

- name: Install Repo prereqs
- name: INSTALL - REPO - Install Repo prereqs
apt: name='{{ item }}'
register: _external_dependency_success
until: _external_dependency_success|success
Expand All @@ -31,7 +31,7 @@
- ca-certificates
when: (prereq_ath.rc != 0) or (prereq_cc.rc != 0)

- name: Add Docker CS Repo GPG key
- name: INSTALL - REPO - Add Docker CS Repo GPG key
apt_key:
keyserver: '{{ docker_engine_repo_gpg_key_server }}'
id: '{{ docker_engine_repo_cs_gpg_key }}'
Expand All @@ -41,7 +41,7 @@
delay: '{{ external_dependency_delay }}'
when: docker_engine_commercial_support|bool == true

- name: Add Docker Open Source Repo GPG key
- name: INSTALL - REPO - Add Docker Open Source Repo GPG key
apt_key:
keyserver: '{{ docker_engine_repo_gpg_key_server }}'
id: '{{ docker_engine_repo_os_gpg_key }}'
Expand All @@ -51,7 +51,7 @@
delay: '{{ external_dependency_delay }}'
when: not docker_engine_commercial_support|bool == true

- name: Add Docker Repo
- name: INSTALL - REPO - Add Docker Repo
template:
src: templates/engine/apt_docker_engine_repo.j2
dest: /etc/apt/sources.list.d/docker.list
Expand All @@ -60,7 +60,7 @@
mode: '0644'
register: update_apt_cache

- name: Update Cache to Add Docker Repo
- name: INSTALL - REPO - Update Cache to Add Docker Repo
apt: update_cache=yes
register: _external_dependency_success
until: _external_dependency_success|success
Expand Down
6 changes: 3 additions & 3 deletions tasks/engine/main.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---

- name: Configure Docker Engine Repo
- name: INSTALL - Configure Docker Engine Repo
include: '{{ ansible_os_family|lower }}/repo.yml'
when: docker_manage_engine_repo|bool == true

- name: Install and Configure Docker Engine
- name: INSTALL - Install and Configure Docker Engine
include: '{{ ansible_os_family|lower }}/engine_install.yml'

- name: Configure Docker Engine Users and Groups
- name: INSTALL - Configure Docker Engine Users and Groups
include: 'users_and_groups.yml'
when: (docker_manage_engine_users|bool == true) and (docker_engine_users is defined)
14 changes: 7 additions & 7 deletions tasks/engine/redhat/engine_install.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
---

- name: Install Docker Engine
- name: INSTALL - ENGINE - Install Docker Engine
package: name='docker-engine-{{ docker_engine_version }}*' state=present
register: _external_dependency_success
until: _external_dependency_success|success
retries: '{{ external_dependency_retries }}'
delay: '{{ external_dependency_delay }}'
when: (docker_engine_version is defined) and (docker_engine_version is not none)

- name: Install Latest Docker Engine
- name: INSTALL - ENGINE - Install Latest Docker Engine
package: name='docker-engine' state=latest
register: _external_dependency_success
until: _external_dependency_success|success
retries: '{{ external_dependency_retries }}'
delay: '{{ external_dependency_delay }}'
when: (docker_engine_version is not defined) or (docker_engine_version is none)

- name: Create Docker Systemd DropIn Directory
- name: INSTALL - ENGINE - Create Docker Systemd DropIn Directory
file: name='/etc/systemd/system/docker.service.d' state=directory recurse=yes

- name: Create Docker Systemd DropIn
- name: INSTALL - ENGINE - Create Docker Systemd DropIn
template:
src: templates/engine/systemd-config.j2
dest: /etc/systemd/system/docker.service.d/docker-opts.conf
Expand All @@ -28,15 +28,15 @@
mode: '0644'
register: _docker_engine_cfg

- name: Execute Systemd Daemon-Reload
- name: INSTALL - ENGINE - Execute Systemd Daemon-Reload
command: systemctl daemon-reload
when: _docker_engine_cfg.changed

- name: Start Docker Engine Service
- name: INSTALL - ENGINE - Start Docker Engine Service
service: name=docker enabled=true state=started
register: _docker_engine_svc
when: _docker_engine_cfg.changed

- name: Restart Docker Engine Service
- name: INSTALL - ENGINE - Restart Docker Engine Service
service: name=docker enabled=true state=restarted sleep=5
when: (_docker_engine_cfg.changed) and ( not _docker_engine_svc.changed)
8 changes: 4 additions & 4 deletions tasks/engine/redhat/repo.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---

- name: Add Docker Repo
- name: INSTALL - REPO - Add Docker Repo
template:
src: templates/engine/yum_docker_engine_repo.j2
dest: /etc/yum.repos.d/Docker.repo
src: templates/engine/yum_docker_engine_repo.j2
dest: /etc/yum.repos.d/Docker.repo
owner: root
group: root
group: root
mode: '0644'
4 changes: 2 additions & 2 deletions tasks/engine/users_and_groups.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---

- name: Create Docker Engine Group
- name: INSTALL - USERS - Create Docker Engine Group
group: name=docker system=yes state=present

- name: Add Users to Docker Engine group
- name: INSTALL - USERS - Add Users to Docker Engine group
user: name='{{ item }}' append=yes groups=docker state=present
with_items: '{{ docker_engine_users|default([]) }}'
Loading

0 comments on commit 51eab69

Please sign in to comment.