Skip to content

Commit

Permalink
Merge pull request #2 from ninthnails/master
Browse files Browse the repository at this point in the history
Add support for RedHat based systems
  • Loading branch information
JasonGiedymin committed Aug 6, 2015
2 parents 3586a74 + bde27f8 commit e94f903
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 11 deletions.
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
language: python
python: "2.7"

env:
- SITE=playbook.yml

before_install:
- sudo apt-get update -qq
- sudo apt-get install curl -y

install:
- pip install -U ansible

# Add ansible.cfg to pick up roles path.
- "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg"

script:
# Check the role/playbook's syntax.
- "ansible-playbook -i ci/inventory ci/$SITE --syntax-check"

# Run the ansible ci playbook
- "ansible-playbook -i ci/inventory ci/playbook.yml --connection=local --sudo -vvvv"
2 changes: 2 additions & 0 deletions ci/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[local]
localhost
13 changes: 13 additions & 0 deletions ci/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
#
# Test Playbook
#

- hosts: localhost
connection: local
sudo: yes

roles:
- {role: ../../}

- include: tests.yml
11 changes: 11 additions & 0 deletions ci/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

- hosts: localhost
connection: local
sudo: yes
gather_facts: false

tasks:
- command: docker run hello-world
register: status
failed_when: status.rc != 0
4 changes: 1 addition & 3 deletions vars/main.yml → defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---
docker_playbook_version: "0.1.2"

# replace with gist variant
docker_repo_key: "36A1D7869245C8950F966E92D8576A8BA88D21E9"
docker_repo: "https://get.docker.io/ubuntu"
docker_opts: ''
docker_create_group: true

##### ---
# Want to advertise the tcp port? Enable below.
Expand Down
7 changes: 0 additions & 7 deletions tasks/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
with_items:
- lxc-docker

- name: Docker default config file
template: src=docker-defaults.j2 dest=/etc/default/docker

- name: Docker init file
template: src=docker-init.j2 dest=/etc/init/docker.conf
notify: Restart Docker

# consider seperate 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
Expand Down
7 changes: 7 additions & 0 deletions tasks/RedHat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

- name: Install Docker Repository
template: src=docker-repo.j2 dest=/etc/yum.repos.d/docker.repo

- name: Install Docker Engine
yum: name=docker-engine state=present

33 changes: 33 additions & 0 deletions tasks/init.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

- name: Check if /etc/init exists
stat: path=/etc/init/
register: etc_init

- name: Docker upstart default config file
template: src=docker-defaults.j2 dest=/etc/default/docker
when: etc_init.stat.exists == true
notify:
- Restart Docker

- name: Docker init file
template: src=docker-init.j2 dest=/etc/init/docker.conf
when: etc_init.stat.exists == true
notify:
- Restart Docker

- name: Check if systemd exists
stat: path=/usr/lib/systemd/system/
register: systemd_check

- name: Docker systemd default config file
template: src=docker-sysconfig.j2 dest=/etc/sysconfig/docker
when: systemd_check.stat.exists == true
notify:
- Restart Docker

- name: Docker systemd file
template: src=docker-service.j2 dest=/lib/systemd/system/docker.service backup=yes
when: systemd_check.stat.exists == true
notify:
- Restart Docker

14 changes: 14 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
---

- include_vars: "{{ ansible_os_family }}.yml"

- name: Create docker group
group: name=docker state=present system=yes
when: docker_create_group
tags:
- config

- include: Debian.yml
when: ansible_os_family == "Debian"

- include: RedHat.yml
when: ansible_os_family == "RedHat"

- include: init.yml
2 changes: 1 addition & 1 deletion templates/docker-defaults.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Generated by Ansible for {{ansible_fqdn}}

DOCKER_OPTS={{docker_opts}}
DOCKER_OPTS={{docker_opts}}
6 changes: 6 additions & 0 deletions templates/docker-repo.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[dockerrepo]
name=Docker Repository
baseurl={{ docker_yum_repo }}
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
20 changes: 20 additions & 0 deletions templates/docker-service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# {{ansible_managed}}

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket
Requires=docker.socket

[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/docker
ExecStart=/usr/bin/docker -d -H fd:// $OPTIONS
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity

[Install]
WantedBy=multi-user.target
Also=docker.socket
6 changes: 6 additions & 0 deletions templates/docker-sysconfig.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# {{ansible_managed}}

OPTIONS={{docker_opts}}

# CentOS 6, RHEL 6
other_args={{docker_opts}}
3 changes: 3 additions & 0 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# replace with gist variant
docker_repo_key: "36A1D7869245C8950F966E92D8576A8BA88D21E9"
docker_repo: "https://get.docker.io/ubuntu"
4 changes: 4 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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 }}"

0 comments on commit e94f903

Please sign in to comment.