Skip to content

Commit

Permalink
feat: add basic role implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
escalate committed Jan 29, 2018
1 parent 3432d82 commit d05a5c4
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 2 deletions.
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
# ansible-ha-bridge-docker
Manages ha-bridge Docker container with systemd on Raspbian and Debian OS
# Ansible Role: ha-bridge-docker

An Ansible role that manages ha-bridge Docker container with systemd on Raspbian and Debian OS.
This role is compatible with OS version Stretch (9) and Jessie (8).

## Requirements

The Docker daemon should be already installed and running on the host side.
I recommend using of the Ansible Galaxy role [angstwad.docker_ubuntu](https://github.com/angstwad/docker.ubuntu) to manage the Docker daemon.

This role is tested with Ansible version greater equal 2.4.

## Install

```
$ ansible-galaxy install escalate.ha-bridge-docker
```

## Role Variables

Please see [defaults/main.yml](https://github.com/escalate/ansible-ha-bridge-docker/blob/master/defaults/main.yml) for a complete list of variables that can be overridden.

## Dependencies

None

## Example Playbook

```
- hosts: all
roles:
- escalate.ha-bridge-docker
```

## License

MIT
13 changes: 13 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---

ha_bridge_docker_image_version: latest
ha_bridge_docker_image_name: aptalca/home-automation-bridge
ha_bridge_docker_run_options: "--volume={{ha_bridge_data_path}}:/ha-bridge/data --volume={{ha_bridge_exec_path}}:/ha-bridge/exec"
ha_bridge_docker_restart_container: always

ha_bridge_http_port: 8080
ha_bridge_security_key: 'secret'

ha_bridge_path: /opt/ha-bridge
ha_bridge_data_path: "{{ha_bridge_path}}/data"
ha_bridge_exec_path: "{{ha_bridge_path}}/exec"
10 changes: 10 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

- name: Reload Systemd daemon
systemd:
daemon_reload: yes

- name: Restart HA-Bridge service
service:
name: docker.ha-bridge
state: restarted
23 changes: 23 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
galaxy_info:
author: Felix Boerner
description: Manages ha-bridge Docker container with systemd on Raspbian and Debian OS
company: Felix Boerner
license: MIT
min_ansible_version: 2.4
github_branch: master
platforms:
- name: Debian
versions:
- jessie
- stretch
galaxy_tags:
- raspbian
- raspberry
- pi
- raspberrypi
- docker
- systemd
- ha
- bridge
- habridge
dependencies: []
55 changes: 55 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---

- name: Load HA-Bridge settings for ARMv7 systems
include_vars:
file: armv7.yml
when: ansible_architecture == 'armv7l'
tags:
- ha-bridge

- name: Create HA-Bridge folder structure
file:
path: "{{item}}"
state: directory
owner: root
group: root
mode: 0755
with_items:
- "{{ha_bridge_path}}"
tags:
- ha-bridge

- name: Create HA-Bridge startup script
template:
src: docker.ha-bridge.service.j2
dest: /etc/systemd/system/docker.ha-bridge.service
owner: root
group: root
mode: 0644
notify:
- Reload Systemd daemon
- Restart HA-Bridge service
tags:
- ha-bridge

- name: Force all notified handlers to run at this point
meta: flush_handlers

- name: Start HA-Bridge service
service:
name: docker.ha-bridge
state: started
enabled: yes
tags:
- ha-bridge

- name: Wait for HA-Bridge service startup
uri:
url: "http://localhost:{{ha_bridge_http_port}}/"
status_code: 200
register: result
until: result.status == 200
retries: 60
delay: 5
tags:
- ha-bridge
16 changes: 16 additions & 0 deletions templates/docker.ha-bridge.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Docker HA-Bridge Container
After=docker.service
Requires=docker.service

[Service]
ExecStartPre=-/usr/bin/docker stop %n
ExecStartPre=-/usr/bin/docker rm %n
ExecStartPre=/usr/bin/docker pull {{ha_bridge_docker_image_name}}:{{ha_bridge_docker_image_version}}
ExecStart=/usr/bin/docker run --init --name %n --net=host --volume=/etc/localtime:/etc/localtime:ro --volume=/etc/timezone:/etc/timezone:ro {{ha_bridge_docker_run_options}} {{ha_bridge_docker_image_name}}:{{ha_bridge_docker_image_version}} -Dserver.port={{ha_bridge_http_port}} -Djava.net.preferIPv4Stack=true -Dexec.garden=/ha-bridge/exec -Dsecurity.key={{ha_bridge_security_key}}
ExecStop=/usr/bin/docker stop %n
TimeoutStartSec=0
Restart={{ha_bridge_docker_restart_container}}

[Install]
WantedBy=multi-user.target
3 changes: 3 additions & 0 deletions vars/armv7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

ha_bridge_docker_image_name: habridge/ha-bridge-raspberrypi3

0 comments on commit d05a5c4

Please sign in to comment.