From be3f6de23299e07b6fee302b98be262a1b6fc223 Mon Sep 17 00:00:00 2001 From: Benoit Carriere Date: Fri, 28 Aug 2015 09:51:33 -0400 Subject: [PATCH 1/4] CircleCI build file. --- circle.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..b867c75 --- /dev/null +++ b/circle.yml @@ -0,0 +1,18 @@ +machine: + pre: + - sudo apt-get update -qq + - sudo apt-get install curl -y + +dependencies: + pre: + - sudo pip install -U ansible + post: + - sudo echo '[defaults]' >> ansible.cfg + - sudo echo 'roles_path = ../' >> ansible.cfg + +test: + override: + - ansible-playbook -i ci/inventory ci/playbook.yml --syntax-check + - ansible-playbook -i ci/inventory ci/playbook.yml --connection=local --sudo -vvvv + + From 8a48d3a24272183aa2fe06d5f9a2d9bcaa980b82 Mon Sep 17 00:00:00 2001 From: Benoit Carriere Date: Mon, 19 Oct 2015 16:53:00 -0400 Subject: [PATCH 2/4] Add Vagrantfile for manual testing. --- .gitignore | 2 ++ Vagrantfile | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .gitignore create mode 100644 Vagrantfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86a37fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vagrant + diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..287cbae --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,40 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure("2") do |config| + config.ssh.forward_agent = true + config.vm.synced_folder Dir.getwd, "/home/vagrant/roles/ansible-docker", nfs: true + + # ubuntu 12.04 that Travis CI is using + config.vm.define 'travis', primary: true do |c| + c.vm.network "private_network", ip: "192.168.100.2" + c.vm.box = "precise-server-cloudimg-amd64-vagrant-disk1" + c.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box" + c.vm.provision "shell" do |s| + s.inline = "apt-get update -y; apt-get install python-software-properties; add-apt-repository ppa:rquillo/ansible; apt-get update -y; apt-get install ansible -y" + s.privileged = true + end + end + + # ubuntu 14.04 + config.vm.define 'ubuntu', primary: true do |c| + c.vm.network "private_network", ip: "192.168.100.3" + c.vm.box = "trusty-server-cloudimg-amd64-vagrant-disk1" + c.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" + c.vm.provision "shell" do |s| + s.inline = "apt-get update -y; apt-get install -y software-properties-common; apt-add-repository ppa:ansible/ansible; apt-get update -y; apt-get install -y ansible" + s.privileged = true + end + end + + # centos 7: + config.vm.define 'centos7' do |c| + c.vm.network "private_network", ip: "192.168.100.5" + c.vm.box = "centos/7" + c.vm.provision "shell" do |s| + s.inline = "yum install -y epel-release; yum install -y ansible" + s.privileged = true + end + end + +end From 16c5a1c092d08871316ec86d1234b8368928ea66 Mon Sep 17 00:00:00 2001 From: Benoit Carriere Date: Wed, 21 Oct 2015 11:48:20 -0400 Subject: [PATCH 3/4] Move yum repo URL variable into defaults. Use apt module for Debian. --- README.md | 38 +++++++++++++++++++++++++++++++++++--- defaults/main.yml | 6 ++++-- tasks/Debian.yml | 23 +++++++---------------- templates/docker-repo.j2 | 2 +- vars/RedHat.yml | 1 - vars/main.yml | 1 + 6 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 vars/main.yml diff --git a/README.md b/README.md index fe94f28..40f2402 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,40 @@ -ansible-docker +ansible-docker - Ansible Playbook for Docker ============== -Docker Playbook for Ansible +## Overview -This playbook will install Docker. +The `ansible-docker` role supports the installation and configuration of Docker Engine. It supports Ubuntu and RedHat/Centos. + +## Requirements + +No requirement. + + +## Development + +Changes can be tested by using Vagrant machines configure for this role, see `Vagrantfile`. + +```bash +cd ansible-docker/ +vagrant up {travis|ubuntu|centos7} +vagrant ssh {travis|ubuntu|centos7} + +$ cd roles/ansible-docker/ +$ ansible-playbook -i ci/inventory ci/playbook.yml --connection=local --sudo + +PLAY [localhost] ************************************************************** + +GATHERING FACTS *************************************************************** +ok: [localhost] + +... + +TASK: [command docker run hello-world] **************************************** +changed: [localhost] + +PLAY RECAP ******************************************************************** +localhost : ok=12 changed=1 unreachable=0 failed=0 +``` Support open source! + diff --git a/defaults/main.yml b/defaults/main.yml index 2c1aa29..6d498bc 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,7 @@ --- -docker_playbook_version: "0.1.2" +# RedHat: Docker yum repository URL +docker_yum_repo: "https://yum.dockerproject.org/repo/main/{{ ansible_distribution | lower }}/{{ os_version_major }}" +docker_yum_repo_gpg: 'https://yum.dockerproject.org/gpg' docker_opts: '' docker_create_group: true @@ -12,7 +14,7 @@ docker_service_start_timeout: '' # use system default value # - uncomment `docker_opts` or provide it as a override # # Note: -# By setting `-H` opt for docker, it will no longer be listenting +# By setting `-H` opt for docker, it will no longer be listening # on the socket. You cannot have both. You must choose socket `-d` # or tcp `-H`. # diff --git a/tasks/Debian.yml b/tasks/Debian.yml index 7121a2b..9840ae3 100644 --- a/tasks/Debian.yml +++ b/tasks/Debian.yml @@ -1,26 +1,17 @@ -- name: Get uname - command: uname -r - register: os_uname - -# would rather have used ansible apt-key... +--- - name: Add specific key - command: apt-key adv --keyserver keyserver.ubuntu.com --recv-keys {{docker_repo_key}} - -- name: Update - command: apt-get update + apt_key: id={{docker_repo_key}} keyserver=keyserver.ubuntu.com state=present - name: Install https apt transport package - command: apt-get install -y apt-transport-https + apt: pkg=apt-transport-https state=present update_cache=yes - name: Add docker repo - command: sudo sh -c "echo deb {{docker_repo}} docker main > /etc/apt/sources.list.d/docker.list" + apt_repository: repo='deb {{ docker_repo }} docker main' state=present - name: Install lxc-docker package - apt: pkg={{item}} state=present update_cache=yes - with_items: - - lxc-docker + apt: pkg=lxc-docker state=present update_cache=yes -# consider seperate role here +# consider separate role here - name: Change ufw forward policy to ACCEPT command: sed -i 's/DEFAULT_FORWARD_POLICY="DROP"/DEFAULT_FORWARD_POLICY="ACCEPT"/g' /etc/default/ufw when: docker_listen_tcp == True @@ -29,6 +20,6 @@ command: ufw reload when: docker_listen_tcp == True -- name: Allow incomming tcp traffic on {{docker_listen_port}} +- name: Allow incoming tcp traffic on {{docker_listen_port}} command: ufw allow {{docker_listen_port}}/tcp when: docker_listen_tcp == True diff --git a/templates/docker-repo.j2 b/templates/docker-repo.j2 index d6a0dd2..ed9e911 100644 --- a/templates/docker-repo.j2 +++ b/templates/docker-repo.j2 @@ -3,4 +3,4 @@ name=Docker Repository baseurl={{ docker_yum_repo }} enabled=1 gpgcheck=1 -gpgkey=https://yum.dockerproject.org/gpg +gpgkey={{ docker_yum_repo_gpg }} diff --git a/vars/RedHat.yml b/vars/RedHat.yml index afb3881..e9431df 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -1,4 +1,3 @@ os_version: "{{ ansible_lsb.release if ansible_lsb is defined else ansible_distribution_version }}" os_version_major: "{{ os_version | regex_replace('^([0-9]+)[^0-9]*.*', '\\\\1') }}" -docker_yum_repo: "https://yum.dockerproject.org/repo/main/{{ ansible_distribution | lower }}/{{ os_version_major }}" diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..307d69d --- /dev/null +++ b/vars/main.yml @@ -0,0 +1 @@ +docker_playbook_version: "0.1.3" From 13923ac87750795fa4e7b3387474a30dfb7a16bd Mon Sep 17 00:00:00 2001 From: Benoit Carriere Date: Wed, 21 Oct 2015 11:53:53 -0400 Subject: [PATCH 4/4] Remove CircleCI file. --- circle.yml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 circle.yml diff --git a/circle.yml b/circle.yml deleted file mode 100644 index b867c75..0000000 --- a/circle.yml +++ /dev/null @@ -1,18 +0,0 @@ -machine: - pre: - - sudo apt-get update -qq - - sudo apt-get install curl -y - -dependencies: - pre: - - sudo pip install -U ansible - post: - - sudo echo '[defaults]' >> ansible.cfg - - sudo echo 'roles_path = ../' >> ansible.cfg - -test: - override: - - ansible-playbook -i ci/inventory ci/playbook.yml --syntax-check - - ansible-playbook -i ci/inventory ci/playbook.yml --connection=local --sudo -vvvv - -