Skip to content

Commit

Permalink
Added vagrant testing
Browse files Browse the repository at this point in the history
Configuration improvements
  • Loading branch information
chirkin committed Aug 31, 2016
1 parent 4c4166c commit e1434cb
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vagrant
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
language: python
python: "2.7"
dist: xenial

# Use the new container infrastructure
sudo: false
sudo: required

# Install ansible
addons:
Expand All @@ -23,7 +24,7 @@ install:

script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
- ansible-playbook tests/travis/travis.yml -i tests/travis/inventory --syntax-check

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
webhooks: https://galaxy.ansible.com/api/v1/notifications/
23 changes: 23 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

ENV['ANSIBLE_ROLES_PATH'] = "../"

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.hostname = "ansible-role-docker"

config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
v.customize ["modifyvm", :id, "--memory", "256"]
end

config.vm.provision "ansible" do |ansible|
ansible.playbook = "tests/vagrant.yml"
# ansible.inventory_path = "tests/inventory"
ansible.verbose = "vv"
ansible.limit = "all"
end
end
16 changes: 16 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
---
docker_apt_cache_valid_time: 3600

# apt repository key url
apt_key_url: hkp://p80.pool.sks-keyservers.net:80
# apt repository key signature
apt_key_sig: 58118E89F3A912897C070ADBF76221572C52609D
# apt repository name for docker
apt_repository: deb https://apt.dockerproject.org/repo ubuntu-{{ ansible_distribution_release }} main

docker_opts: ""

# check new docker package version
docker_update: no

docker_py_install: true
docker_py_version: latest
7 changes: 7 additions & 0 deletions docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- hosts: all
become: yes
roles:
- { role: ./,
docker_opts: "-H unix:///var/run/docker.sock"
}
110 changes: 91 additions & 19 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,105 @@
---
- name: add docker repo apt key
- name: check ubuntu version
fail:
msg: "{{ ansible_distribution_version }} is not an acceptable version of Ubuntu for this role"
when: ansible_distribution_version|version_compare(15.04, '<')

- name: add docker repository key
apt_key:
keyserver=p80.pool.sks-keyservers.net
id=58118E89F3A912897C070ADBF76221572C52609D
state=present
keyserver: "{{ apt_key_url }}"
id: "{{ apt_key_sig }}"
state: present

- name: add docker repository
apt_repository:
repo="deb https://apt.dockerproject.org/repo ubuntu-xenial main"
update_cache=yes
repo: "{{ apt_repository }}"
update_cache: yes

- name: install docker
apt: name=docker-engine
- name: install docker package
apt:
name: docker-engine
state: "{{ 'latest' if docker_update else 'present' }}"
update_cache: yes
cache_valid_time: "{{ docker_apt_cache_valid_time }}"

- name: create /etc/systemd/system/docker.service.d directory
- name: create systemd configuration directory for Docker service
file:
dest=/etc/systemd/system/docker.service.d
recurse=yes
state=directory
dest: /etc/systemd/system/docker.service.d
state: directory
owner: root
group: root
mode: 0755
when: docker_opts != ""

- name: set docker daemon options (systemd)
copy:
content: |
[Service]
Environment="DOCKER_OPTS={{ docker_opts.rstrip('\n') }}"
dest: /etc/systemd/system/docker.service.d/env.conf
owner: root
group: root
mode: 0644
notify:
- reload systemd
- restart docker
when: docker_opts != ""

- name: uploads docker configuration file
- name: create docker daemon configuration file
template:
src: 'docker/docker.conf.j2'
dest: '/etc/systemd/system/docker.service.d/docker.conf'
src: docker.conf
dest: /etc/systemd/system/docker.service.d/docker.conf
notify:
- 'daemon-reload'
- 'restart docker'
- reload systemd
- restart docker
when: docker_opts != ""

- name: install pip, python-dev package with apt
apt:
pkg: "{{ item }}"
state: latest
update_cache: yes
cache_valid_time: "{{ docker_apt_cache_valid_time }}"
with_items:
- python-dev
- python-pip

- name: upgrade latest docker-py
pip:
name: "{{ item.name }}"
state: latest
with_items:
- { name: docker-py, version: "{{ docker_py_version }}", install: "{{ docker_py_install }}" }
when: (item.version=="latest" and item.install)

- name: install docker-py
pip: name=docker-py
pip:
name: "{{ item.name }}"
state: present
version: "{{ item.version }}"
with_items:
- { name: docker-py, version: "{{ docker_py_version }}", install: "{{ docker_py_install }}" }
when: (item.version!="latest" and item.install)

- name: check if /etc/updatedb.conf exists
stat:
path: /etc/updatedb.conf
register: _updatedb_conf_exists

- name: ensure updatedb does not index /var/lib/docker
lineinfile:
dest: /etc/updatedb.conf
state: present
backrefs: yes
regexp: '^PRUNEPATHS="(/var/lib/docker )?(.*)"$'
line: 'PRUNEPATHS="/var/lib/docker \2"'
when: _updatedb_conf_exists.stat.exists

- name: start docker
service:
name: docker
state: started

- meta: flush_handlers
- name: update facts if docker0 is not defined
action: setup filter="ansible_docker0"
when: ansible_docker0 is not defined
3 changes: 3 additions & 0 deletions templates/docker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// $DOCKER_OPTS
1 change: 0 additions & 1 deletion tests/inventory

This file was deleted.

2 changes: 2 additions & 0 deletions tests/travis/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[local]
localhost ansible_connection=local
4 changes: 2 additions & 2 deletions tests/test.yml → tests/travis/travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- hosts: localhost
remote_user: root
- hosts: all
become: yes
roles:
- ansible-role-docker
5 changes: 5 additions & 0 deletions tests/vagrant/vagrant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: all
become: yes
roles:
- ansible-role-docker

0 comments on commit e1434cb

Please sign in to comment.