From da3eb9cf1c302c6ec15d70663278e386bd8a4993 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Thu, 23 Feb 2017 22:08:18 -0600 Subject: [PATCH] Initial commit. --- .travis.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ README.md | 35 +++++++++++++++++++++++++++++++++++ defaults/main.yml | 5 +++++ handlers/main.yml | 3 +++ meta/main.yml | 29 +++++++++++++++++++++++++++++ tasks/main.yml | 15 +++++++++++++++ tasks/setup-Debian.yml | 20 ++++++++++++++++++++ tasks/setup-RedHat.yml | 13 +++++++++++++ tests/test.yml | 13 +++++++++++++ 9 files changed, 175 insertions(+) create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 tasks/setup-Debian.yml create mode 100644 tasks/setup-RedHat.yml create mode 100644 tests/test.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a2e48eb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,42 @@ +--- +services: docker + +env: + - distro: centos7 + init: /usr/lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + - distro: ubuntu1604 + init: /lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + - distro: ubuntu1404 + init: /sbin/init + run_opts: "" + +before_install: + # Pull container. + - 'docker pull geerlingguy/docker-${distro}-ansible:latest' + +script: + - container_id=$(mktemp) + # Run container in detached state. + - 'docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"' + + # Ansible syntax check. + - 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check' + + # Test role. + - 'docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml' + + # Test role idempotence. + - idempotence=$(mktemp) + - docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | tee -a ${idempotence} + - > + tail ${idempotence} + | grep -q 'changed=0.*failed=0' + && (echo 'Idempotence test: pass' && exit 0) + || (echo 'Idempotence test: fail' && exit 1) + + # TODO: Test whether Docker is running correctly. + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..01ba826 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Ansible Role: Docker + +[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-docker.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-docker) + +An Ansible Role that installs [Docker](https://www.docker.com) on Debian/Ubuntu. + +## Requirements + +None. + +## Role Variables + +Available variables are listed below, along with default values (see `defaults/main.yml`): + + TODO. + +TODO. + +## Dependencies + +None. + +## Example Playbook + + - hosts: all + roles: + - geerlingguy.docker + +## License + +MIT / BSD + +## Author Information + +This role was created in 2017 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..2e61d13 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,5 @@ +--- +docker_package: "docker-engine" + +# Used only for Debian/Ubuntu. Add 'testing' if you don't want stable. +docker_apt_repository: "deb https://apt.dockerproject.org/repo {{ ansible_distribution|lower }}-{{ ansible_distribution_release }} main" diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..43016e0 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart docker + service: name=docker state=restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..b975c01 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,29 @@ +--- +dependencies: [] + +galaxy_info: + author: geerlingguy + description: Docker for Linux. + company: "Midwestern Mac, LLC" + license: "license (BSD, MIT)" + min_ansible_version: 2.0 + platforms: + - name: EL + versions: + - 6 + - 7 + - name: Debian + versions: + - jessie + - name: Ubuntu + versions: + - trusty + - xenial + galaxy_tags: + - web + - system + - containers + - docker + - orchestration + - compose + - server diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..51e6c5e --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,15 @@ +--- +- include: setup-RedHat.yml + when: ansible_os_family == 'RedHat' + +- include: setup-Debian.yml + when: ansible_os_family == 'Debian' + +- name: Install Docker. + package: name={{ docker_package }} state=present + +- name: Ensure Docker is started and enabled at boot. + service: + name: docker + state: started + enabled: yes diff --git a/tasks/setup-Debian.yml b/tasks/setup-Debian.yml new file mode 100644 index 0000000..d88b8a4 --- /dev/null +++ b/tasks/setup-Debian.yml @@ -0,0 +1,20 @@ +--- +- name: Ensure depdencies are installed. + apt: + name: "{{ item }}" + state: present + with_items: + - apt-transport-https + - ca-certificates + +- name: Add Docker apt key. + apt_key: + url: https://apt.dockerproject.org/gpg + id: 58118E89F3A912897C070ADBF76221572C52609D + state: present + +- name: Add Docker repository. + apt_repository: + repo: "{{ docker_apt_repository }}" + state: present + update_cache: yes diff --git a/tasks/setup-RedHat.yml b/tasks/setup-RedHat.yml new file mode 100644 index 0000000..69c1319 --- /dev/null +++ b/tasks/setup-RedHat.yml @@ -0,0 +1,13 @@ +--- +# - name: Add Docker GPG key. +# rpm_key: +# key: https://apt.dockerproject.org/gpg +# state: present + +- name: Add Docker repository. + yum_repository: + name: docker + description: Docker repository. + baseurl: https://docs.docker.com/engine/installation/linux/repo_files/centos/docker.repo + gpgkey: https://apt.dockerproject.org/gpg + gpgcheck: yes diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..cdbbb3f --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,13 @@ +--- +- hosts: all + + pre_tasks: + - name: Update apt cache. + apt: update_cache=yes cache_valid_time=600 + when: ansible_os_family == 'Debian' + + - name: Install test dependencies. + package: name=curl state=present + + roles: + - role_under_test