-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
245 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
language: python | ||
python: "3.6" | ||
sudo: required | ||
matrix: | ||
fast_finish: true | ||
before_install: | ||
- sudo apt-get update -qq | ||
- sudo apt-get install -qq python-apt | ||
install: | ||
- pip install ansible ansible-lint | ||
- pip --version | ||
- python --version | ||
- ansible --version | ||
- "printf '[defaults]\nroles_path = ../' > ansible.cfg" | ||
- git clone https://github.com/pyslackers/ansible-role-python ../pyslackers.python | ||
script: | ||
- ansible-lint tasks/main.yml | ||
- ansible-playbook -i tests/inventory --syntax-check --list-tasks tests/test.yml | ||
- ansible-playbook -i tests/inventory --connection=local --become -vvvv tests/test.yml -u root --skip-tags travis-exempt | ||
- > | ||
ansible-playbook -i tests/inventory --connection=local --become -vvvv tests/test.yml -u root --skip-tags travis-exempt | ||
| grep -q 'changed=0.*failed=0' | ||
&& (echo 'Idempotence test: pass' && exit 0) | ||
|| (echo 'Idempotence test: fail' && exit 1) | ||
- cat /etc/systemd/system/api-hour-demo.socket | ||
- cat /etc/systemd/system/api-hour-demo.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,63 @@ | ||
# ansible-role-api-hour | ||
Ansible role to install and configure an API-Hour daemon | ||
eyepea.api-hour | ||
======== | ||
|
||
[![Build Status](https://travis-ci.org/eyepea/ansible-role-api-hour.svg?branch=master)](https://travis-ci.org/eyepea/ansible-role-api-hour) | ||
|
||
Ansible role to install and configure an [API-Hour](https://github.com/Eyepea/API-Hour) daemon. | ||
|
||
Installation | ||
------------ | ||
|
||
To install this roles clone it into your roles directory. | ||
|
||
```bash | ||
$ git clone https://github.com/eyepea/ansible-role-api-hour.git eyepea.api-hour | ||
``` | ||
|
||
If your playbook already reside inside a git repository you can clone it by using git submodules. | ||
|
||
```bash | ||
$ git submodule add -b master https://github.com/eyepea/ansible-role-api-hour.git eyepea.api-hour | ||
``` | ||
|
||
Requirements | ||
------------ | ||
|
||
The [pyslakcers.python](https://github.com/pyslackers/ansible-role-python) is required to install python. Install it | ||
with one of these commands: | ||
|
||
```bash | ||
$ git clone https://github.com/pyslackers/ansible-role-python.git pyslackers.python | ||
``` | ||
|
||
```bash | ||
$ git submodule add -b master https://github.com/pyslackers/ansible-role-python.git pyslackers.python | ||
``` | ||
|
||
Role Variables | ||
-------------- | ||
|
||
* `ah_name`: Name of the daemon. | ||
* `ah_git_url`: Git url to clone daemon. | ||
* `ah_python_version`: Python version required for the daemon. | ||
* `ah_version`: Version to clone (default to `master`). | ||
* `ah_requirements_path`: Path to python requirements file (default to `requirements.txt`). | ||
* `ah_sockets`: List of listening sockets (default to `[0.0.0.0:8000]`). | ||
|
||
Example Playbook | ||
---------------- | ||
|
||
```yml | ||
- hosts: localhost | ||
vars: | ||
ah_name: api-hour-demo | ||
ah_git_url: https://github.com/Eyepea/api-hour-demo.git | ||
ah_python_version: 3.6.3 | ||
roles: | ||
- eyepea.api-hour | ||
``` | ||
License | ||
------- | ||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
|
||
ah_version: master | ||
ah_requirements_path: requirements.txt | ||
ah_sockets: | ||
- 0.0.0.0:8000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
|
||
- name: Restart socket | ||
systemd: | ||
name: "{{ ah_name }}.socket" | ||
daemon-reload: True | ||
state: restarted | ||
when: "'travis' not in group_names" | ||
|
||
- name: Restart service | ||
systemd: | ||
name: "{{ ah_name }}.service" | ||
daemon-reload: True | ||
state: restarted | ||
when: "'travis' not in group_names" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
|
||
- name: Install packages Debian | ||
apt: | ||
name: "{{item}}" | ||
state: present | ||
when: ansible_os_family == 'Debian' | ||
with_items: | ||
- git | ||
|
||
- name: Install packages CentOS | ||
yum: | ||
name: "{{item}}" | ||
state: present | ||
when: ansible_os_family == 'RedHat' | ||
with_items: | ||
- git | ||
|
||
- name: Clone project | ||
git: | ||
repo: "{{ ah_git_url }}" | ||
dest: "/opt/{{ ah_name }}" | ||
force: yes | ||
version: "{{ ah_version }}" | ||
notify: | ||
- Restart service | ||
|
||
- name: Link directories | ||
file: | ||
src: "/opt/{{ ah_name }}/etc" | ||
dest: "/etc/{{ ah_name }}" | ||
state: link | ||
|
||
- name: Install python | ||
include_role: | ||
name: pyslackers.python | ||
vars: | ||
virtualenvs: | ||
"{{ ah_name }}": | ||
path: "/opt/{{ ah_name }}/.env" | ||
version: "{{ ah_python_version }}" | ||
requirements: "/opt/{{ ah_name }}/{{ ah_requirements_path }}" | ||
|
||
- name: Create systemd directories | ||
file: | ||
path: /etc/systemd/system | ||
state: directory | ||
|
||
- name: Configure systemd socket | ||
template: | ||
src: etc/systemd/system/project.socket.j2 | ||
dest: "/etc/systemd/system/{{ ah_name }}.socket" | ||
force: yes | ||
notify: | ||
- Restart socket | ||
|
||
- name: Enable systemd socket | ||
tags: | ||
- travis-exempt | ||
systemd: | ||
daemon_reload: yes | ||
name: "{{ ah_name }}.socket" | ||
enabled: True | ||
masked: False | ||
|
||
- name: Configure systemd service | ||
template: | ||
src: etc/systemd/system/project.service.j2 | ||
dest: "/etc/systemd/system/{{ ah_name }}.service" | ||
force: yes | ||
notify: | ||
- Restart service | ||
|
||
- name: Enable systemd service | ||
tags: | ||
- travis-exempt | ||
systemd: | ||
name: "{{ ah_name }}.service" | ||
enabled: True | ||
masked: False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# {{ ansible_managed }} | ||
|
||
[Unit] | ||
Description={{ ah_name }} daemon | ||
Requires={{ ah_name }}.socket | ||
After=network.target | ||
AssertPathExists=/opt/{{ ah_name }}/.env/bin/api_hour | ||
AssertPathExists=/etc/{{ ah_name }} | ||
AssertPathExists=/opt/{{ ah_name }}/{{ ah_name }}/__init__.py | ||
|
||
[Service] | ||
Type=simple | ||
PIDFile=/run/lock/{{ ah_name }}.pid | ||
User=root | ||
Group=root | ||
Environment="PYTHONPATH=." | ||
Environment="PYTHONUNBUFFERED=true" | ||
WorkingDirectory=/opt/{{ ah_name }} | ||
ExecStart=/opt/{{ ah_name }}/.env/bin/api_hour -ac {{ ah_name }}:Container | ||
ExecReload=/bin/kill -s HUP $MAINPID | ||
ExecStop=/bin/kill -s TERM $MAINPID | ||
PrivateTmp=true | ||
Restart=always | ||
RestartSec=4 | ||
KillSignal=SIGTERM | ||
SendSIGKILL=yes | ||
LimitNOFILE=65535 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# {{ ansible_managed }} | ||
|
||
[Unit] | ||
Description={{ ah_name }} socket | ||
|
||
[Socket] | ||
{% for socket in ah_sockets %} | ||
|
||
ListenStream={{ socket }} | ||
{% endfor %} | ||
|
||
[Install] | ||
WantedBy=sockets.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[travis] | ||
localhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
|
||
- hosts: localhost | ||
vars: | ||
ah_name: api-hour-demo | ||
ah_git_url: https://github.com/Eyepea/api-hour-demo.git | ||
ah_python_version: 3.6.3 | ||
roles: | ||
- ansible-role-api-hour |