Skip to content

Commit

Permalink
Added ansible deploy role (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Fleischer <[email protected]>
  • Loading branch information
JohannesFleischer and Johannes Fleischer authored Jun 25, 2023
1 parent 9c3bd1d commit 6d66485
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Custom
films/*
poster/*
mongo/db
films/
poster/
mongo/db/
ansible/collections/
!.gitkeep

# Logs
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Start

The [Production](#production) and [Development](#development) sections include informations to manually install the project. If you want to use a raspberry pi to host the project there is also a [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) role in this repository that you can use to install the project and setup a auto start. You can fin more information [here](#information-about-hosting-on-a-pi)

### Production

To run the latest official release download the `docker-compose.yml` and create a `films`, `mongo/db` and `poster` folder (or symlink for your media) in the same directory. So it should look kinda like this:
Expand Down Expand Up @@ -115,9 +117,29 @@ see [here](DEPENDENCIES.md)

### Information about hosting on a pi

To run on a raspberry pi use either the [64-bit version](https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-64-bit) on `raspi 3+`</br>
or [ubuntu for raspberry pi](https://ubuntu.com/download/raspberry-pi) on `raspi 4+`
To run on a raspberry pi use the [64-bit version](https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-64-bit) on `raspi 3` or higher

For the installation and the setup of the autostart you can use Ansible role in `./ansible/`

> **IMPORTANT:** Ansible run on your pc, <u>not on your pi</u> and executes commands via a ssh connection. To use the role a [passwordless ssh connection](https://www.ssh.com/academy/ssh/copy-id) to the pi is necessary.
Once that is ensured, you can follow the steps below for installation and setup.

1. [Install Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) on your pc
2. Download the repository on your pc
3. Navigate to the `ansible` folder of the repository
4. Install the requirements with:

```sh
ansible-galaxy install -r requirements.yml
```

5. Customize the variables in the `vars/vars.yml` file to your liking
6. Start the role with:

```sh
ansible-playbook install.yml
```

### Information about remote easyfications

Expand Down
5 changes: 5 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[defaults]
roles_path = ./roles
inventory = ./inventory
collections_paths = ./collections

Empty file added ansible/collections/.gitkeep
Empty file.
9 changes: 9 additions & 0 deletions ansible/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Install senior-movie-selector on a pie
hosts: pi

vars_files:
- vars/vars.yml

roles:
- senior-movie-selector
2 changes: 2 additions & 0 deletions ansible/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pi]
"{{ host_ip_address }}"
3 changes: 3 additions & 0 deletions ansible/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
collections:
- name: community.docker
10 changes: 10 additions & 0 deletions ansible/roles/senior-movie-selector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# General

With this role you can install the [senior-movie-selector](https://github.com/JohannesFleischer/senior-movie-selector) project on a raspberry pi with the raspbian 64-bit OS

Besides the installation there is also a autostart functionality added that automatically restarts the application on startup and starts chromium in fullscreen with the client opened.

## Supported Platforms

tested on and written for raspbian 64bit
the installation probably works also on other Debian based operating systems but the autostart on boot wont work
13 changes: 13 additions & 0 deletions ansible/roles/senior-movie-selector/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---

senior_movie_selector_version: "{{ version }}"

senior_movie_selector_films_path: "{{ films_media_path }}"

senior_movie_selector_poster_path: "{{ poster_media_path }}"

senior_movie_selector_project_dir: "{{ project_dir }}"

senior_movie_selector_project_owner: "{{ host_username }}"

senior_movie_selector_setup_autostart: "{{ setup_autostart }}"
10 changes: 10 additions & 0 deletions ansible/roles/senior-movie-selector/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
galaxy_info:
author: Johannes Fleischer
description: Sets up the Senior-Movie-selector project on raspbian (64bit).

issue_tracker_url: https://github.com/JohannesFleischer/senior-movie-selector/issues

license: All rights reserved.

min_ansible_version: "2.1"

78 changes: 78 additions & 0 deletions ansible/roles/senior-movie-selector/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
- name: Make sure directories exists
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0700"
loop:
- "{{ senior_movie_selector_project_dir }}"
- "{{ senior_movie_selector_project_dir }}/mongo/db"
- "/home/{{ senior_movie_selector_project_owner }}/.config/autostart"

# Create films directory or symlink:
- name: Create 'films' directory if the path is empty
ansible.builtin.file:
path: "{{ senior_movie_selector_project_dir }}/films"
state: directory
mode: "0700"
when: senior_movie_selector_films_path == ""

- name: Make sure the 'films' link exists if the path is not empty
ansible.builtin.file:
src: "{{ senior_movie_selector_films_path }}"
dest: "{{ senior_movie_selector_project_dir }}/films"
state: link
when: senior_movie_selector_films_path != ""

# Create poster directory or symlink:
- name: Make sure the 'poster' directory exists if the path is empty
ansible.builtin.file:
path: "{{ senior_movie_selector_project_dir }}/poster"
state: directory
mode: "0700"
when: senior_movie_selector_poster_path == ""

- name: Make sure the 'poster' link exists if the path is not empty
ansible.builtin.file:
src: "{{ senior_movie_selector_poster_path }}"
dest: "{{ senior_movie_selector_project_dir }}/poster"
state: link
when: senior_movie_selector_poster_path != ""

# Create necessary files
- name: Download docker-compose.yml
ansible.builtin.get_url:
url: "https://raw.githubusercontent.com/JohannesFleischer/senior-movie-selector/{{ senior_movie_selector_version }}/docker-compose.yml"
dest: "{{ senior_movie_selector_project_dir }}/docker-compose.yml"
mode: "0700"

- name: Create autostart files from template if selected
ansible.builtin.template:
src: "{{ item.src_file }}"
dest: "{{ item.dest_file }}"
mode: "0700"
loop:
- {
src_file: "senior-movie-selector.desktop.j2",
dest_file: "/home/{{ senior_movie_selector_project_owner }}/.config/autostart/senior-movie-selector.desktop"
}
- {
src_file: "senior-movie-selector.sh.j2",
dest_file: "/home/{{ senior_movie_selector_project_owner }}/Desktop/senior-movie-selector.sh"
}
when: senior_movie_selector_setup_autostart

- name: Install pip
ansible.builtin.apt:
name: python3-pip

- name: Install docker and docker-compose python package
ansible.builtin.pip:
name:
- docker
- docker-compose

- name: Start senior-movie-selector
community.docker.docker_compose:
project_src: "{{ senior_movie_selector_project_dir }}"
state: present
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Desktop Entry]
Name=Senior Movie Selector
Comment=Startet das senior-movie-selector Project
Type=Application
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Exec=lxterminal -e "/home/{{ senior_movie_selector_project_owner }}/Desktop/senior-movie-selector.sh"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/sh

echo "starting senior-movie-selector"
cd "{{ senior_movie_selector_project_dir }}" && sudo docker compose restart
xhost + && chromium-browser --disable-gpu --start-fullscreen localhost
exit 0
25 changes: 25 additions & 0 deletions ansible/vars/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---

# The name of your pi user
host_username: pi

# The local ip of your pi. The default value is just an example
host_ip_address: "192.168.178.63"

# The release version of the senior-movie-selector project you want to install
version: v1.0.1

# The directory you want the project to be stored in on your pi
project_dir: "/home/{{ host_username }}/senior-movie-selector"

# Path to the media folder with the films if you want to replace the default folders with links to the folder. Leave empty if thats not the case
films_media_path: ""

# Path to the media folder with the poster if you want to replace the default folders with links to the folder. Leave empty if thats not the case
poster_media_path: ""

# With this variable you can choose whether the autostart configuration should be applied.
# When activated this role adds two files that try to pull and restart the project on startup and launch chromium in fullscreen with the Client opened
# Options: true/false
setup_autostart: true

0 comments on commit 6d66485

Please sign in to comment.