Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 26351e9e authored by Arthur BOUDREAULT's avatar Arthur BOUDREAULT
Browse files

refactor: transformed the role into a collection

parent bed20025
No related branches found
No related tags found
1 merge request!22Resolve "Create a collection"
# Rôle Ansible : Yunohost
[🇬🇧 English version](README.md)
Déployez [Yunohost](https://yunohost.org/#/) avec Ansible !
## Prérequis
Aucun.
## Variables du rôle
Les variables par défaut sont disponibles dans `default/main.yml` cependant il est nécessaire de les surcharger selon vos besoins en termes de domaines, d'utilisateurs et d'applications sur Yunohost.
### Installation de Yunohost
```yml
# Script pour Debian 10 uniquement.
ynh_install_script_url: https://install.yunohost.org
ynh_admin_password: MYINSECUREPWD_PLZ_OVERRIDE_THIS
```
- `ynh_install_script_url` est le script d'installation des packages Yunohost, par défaut c'est le script officiel. Yunohost ne s'installe que sur Debian 10.
- `ynh_admin_password` est le mot de passe permettant d'accéder à l’interface d’administration du serveur.
### Gestion des domaines
```yml
# Liste des domaines gérés par Yunohost.
ynh_main_domain: domain.tld
ynh_extra_domains:
- forum.domain.tld
- wiki.domain.tld
ynh_ignore_dyndns_server: False
```
- `ynh_main_domain` correspond au domaine principal qui permet l’accès au serveur ainsi qu’au portail d’authentification des utilisateurs. On peut se contenter d'un nom de domaine qui nous appartient ou en utiliser un en .nohost.me / .noho.st / .ynh.fr (plus d'infos [ici](https://yunohost.org/fr/install/hardware:vps_debian)).
- `ynh_extra_domains` sont des sous-domaines optionnels. Ils permettent d'installer une application par sous-domaine (plus d'infos [ici](https://yunohost.org/fr/dns_subdomains)).
- `ynh_ignore_dyndns_server` permet d'enregistrer les domaines avec un service de DNS dynamique (plus d'infos [ici](https://yunohost.org/fr/dns_dynamicip)).
### Gestion des utilisateurs
```yml
# Liste des utilisateurs Yunohost.
ynh_users:
- name: user1
pass: MYINSECUREPWD_PLZ_OVERRIDE_THIS
firstname: Jane
lastname: Doe
mail_domain: domain.tld
```
- `ynh_users` est la liste des utilisateurs à créer. Chaque champ est obligatoire. Certaines applications Yunohost nécessitent qu'un utilisateur soit administrateur de l'application. Il aura ensuite le droit de gérer l'application depuis l'interface l'administration du serveur. Vous pouvez en apprendre plus sur la gestion des utilisateurs Yunohost [ici](https://yunohost.org/fr/administrate/overview/users).
### Gestion des applications
```yml
# Liste des applications Yunohost.
ynh_apps:
- label: WikiJS
link: wikijs
args:
domain: wiki.domain.tld
path: /
admin: user1
is_public: no
- label: Discourse
link: discourse
args:
domain: forum.domain.tld
path: /
admin: user1
is_public: yes
post_install:
- src: "templates/site_settings.yml.j2"
dest: "/var/www/discourse/config/site_settings.yml"
type: "config"
- src: "templates/configure_discourse.sh.j2"
dest: "/tmp/configure_discourse.sh"
type: "script"
owner: root
group: root
```
- `ynh_apps` est la liste des applications à installer.
- `label` permet de donner un nom personnalisé à l'application sur l'interface utilisateur.
- `link` correspond au nom de l'application Yunohost qu'on veut installer.
#### Concernant les arguments
- `domain` est obligatoire. Il faut choisir un des domaines de son instance Yunohost.
- `path` est obligatoire. Il faut choisir une URL pour accéder à son application comme `domain.tld/my_app`. Utilisez juste `/` si l'application doit s'installer sur un sous-domaine.
- `is_public` est un argument qu'on retrouve souvent. Paramétré sur `yes`, l'application sera accessible à tout le monde, même sans authentification sur le portail SSO Yunohost. Paramétré sur `no`, l'application ne sera accessible qu'après authentification.
Pour les autres arguments, il faut se référer au `manifest.json` disponible dans le dépôt de l'application Yunohost qu'on installe. Vous pouvez en apprendre plus sur cette partie [ici](https://yunohost.org/fr/packaging_apps_manifest).
#### Concernant la post-installation
Il est possible de compléter l'installation des applications par l'ajout de templates jinja de configuration ou de scripts que vous aurez écrit de votre côté.
Pour activer cette fonctionnalité, définissez la variable `post_install` qui correspond à la liste des fichiers de post-installation de votre application.
Cette tâche utilisant le module template, vous pouvez tout à fait utiliser vos propres variables et les appeler dans vos fichiers de template. Pour en savoir sur ce module, cliquez [ici](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html).
- `src` est obligatoire. Il s'agit du répertoire où le fichier de template se situe sur la machine qui execute Ansible.
- `dest` est obligatoire. Il s'agit du répertoire où le fichier de template va être stocké.
- `type` est obligatoire :
- Si vous précisez comme valeur `script` alors le fichier de template aura pour droits 740. Il sera exécuté après son transfert sur le serveur Yunohost (généralement dans `/tmp/`) puis il sera supprimé.
- Si vous précisez comme valeur `config` alors le fichier de template aura pour droits 660. Il sera transféré sur le serveur Yunohost (généralement dans `/var/www/AppName/`) et vous pourrez l'importer avec un script shell à côté par exemple.
Pour `owner` et `group`, par défaut le fichier va prendre comme utilisateur propriétaire le nom de l'application et comme groupe propriétaire www-data (groupe NGINX). Vous pouvez les changer en précisant des valeurs différentes.
## Dépendances
Aucune.
## Exemple de Playbook
```yml
---
- name: Install Yunohost on Debian Server
hosts: all
become: True
collections:
- lydra.yunohost
pre_tasks:
- name: Update all packages and index
ansible.builtin.apt:
upgrade: dist
update_cache: yes
roles:
- ynh_setup
- ynh_config
- ynh_backup
```
## License
[![ansible-yunohost Copyright 2021 Lydra](https://www.gnu.org/graphics/gplv3-with-text-136x68.png)](https://choosealicense.com/licenses/gpl-3.0/)
**ansible-yunohost** est maintenu par [Lydra](https://lydra.fr/) et publié sous la licence GPL3.
# Ansible Role: Yunohost
[🇫🇷 French version](README-FR.md)
Deploy [Yunohost](https://yunohost.org/#/) with Ansible!
## Requirements
None.
## Role Variables
Default variables are available in `default/main.yml` however it is necessary to override them according to your needs for Yunohost domains, users and apps.
### Yunohost Installation
```yml
# Debian 10 script only.
ynh_install_script_url: https://install.yunohost.org
ynh_admin_password: MYINSECUREPWD_PLZ_OVERRIDE_THIS
```
- `ynh_install_script_url` downloads official Yunohost script for installing Yunohost packages. Yunohost is only available on Debian 10.
- `ynh_admin_password` is the password used to access to the server's administration interface.
### Domain management
```yml
# The list of Yunohost domains.
ynh_main_domain: domain.tld
ynh_extra_domains:
- forum.domain.tld
- wiki.domain.tld
ynh_ignore_dyndns_server: False
```
- `ynh_main_domain` is the main domain used by the server's users to access the authentication portal. If you already own a domain name, you probably want to use it here. You can also use a domain in .nohost.me / .noho.st / .ynh.fr (more info [here](https://yunohost.org/en/install/hardware:vps_debian)).
- `ynh_extra_domains` are optional and allow you to install one app per subdomain (more info [here](https://yunohost.org/en/administrate/specific_use_cases/domains/dns_subdomains)).
- `ynh_ignore_dyndns_server` allow to register domains with a Dynamic DNS service (more info [here](https://yunohost.org/en/dns_dynamicip)).
### User management
```yml
# The list of Yunohost users.
ynh_users:
- name: user1
pass: MYINSECUREPWD_PLZ_OVERRIDE_THIS
firstname: Jane
lastname: Doe
mail_domain: domain.tld
```
- `ynh_users` is the list of users to create. Each field is mandatory. Some Yunohost applications require that a user be the app administrator. He will then have the right to manage the application from the server administration interface. You can learn more about Yunohost user management [here](https://yunohost.org/en/users).
### App management
```yml
# The list of Yunohost apps.
ynh_apps:
- label: WikiJS
link: wikijs
args:
domain: wiki.domain.tld
path: /
admin: user1
is_public: no
- label: Discourse
link: discourse
args:
domain: forum.domain.tld
path: /
admin: user1
is_public: yes
post_install:
- src: "templates/site_settings.yml.j2"
dest: "/var/www/discourse/config/site_settings.yml"
type: "config"
- src: "templates/configure_discourse.sh.j2"
dest: "/tmp/configure_discourse.sh"
type: "script"
owner: root
group: root
```
- `ynh_apps` is the list of applications to install.
- `label` allows you to give a custom name to the application on the user interface.
- `link` is the name of the Yunohost application to install.
#### About the arguments
- `domain` is essential. You have to choose one of the domains of your Yunohost instance.
- `path` is required. You have to choose a URL to access your application like `domain.tld/my_app`. Just use `/` if the application is to be installed on a subdomain.
- `is_public` argument is a common one. Set to `yes`, the application will be accessible to everyone, even without authentication to the Yunohost SSO portal. Set to `no`, the application will be accessible only after authentication.
For the other arguments, you have to refer to the `manifest.json` available in the repository of the Yunohost application you install. You can learn more about this part [here](https://yunohost.org/fr/packaging_apps_manifest).
#### About the post-installation
It is possible to complete the installation of applications by adding jinja template configuration files or scripts written by yourself.
To enable this feature, define the `post_install` variable which corresponds to the list of post-installation files of your applications.
Because this task uses the template module, you can use your own variables and call them in your template files. To know more about this module, click [here](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html).
- `src` is mandatory. This is the directory where the template file is located on the machine running Ansible.
- `dest` is mandatory. This is the directory where the template file will be stored.
- `type` is mandatory:
- If you specify `script` as the value, then the template file will have 740 rights. It will be executed after it is transferred to the Yunohost server (usually in `/tmp/`) and then deleted.
- If you specify `config` as the value, then the template file will have 660 rights. It will be transferred to the Yunohost server (usually in `/var/www/AppName/`) and after you could import it with a shell script on the side for example.
For `owner` and `group`, by default the file will take as owner the name of the application and as owner www-data(NGINX group). You can change them by specifying different values.
## Dependencies
None.
## Example Playbook
```yml
---
- name: Install Yunohost on Debian Server
hosts: all
become: True
collections:
- lydra.yunohost
pre_tasks:
- name: Update all packages and index
ansible.builtin.apt:
upgrade: dist
update_cache: yes
roles:
- ynh_setup
- ynh_config
- ynh_backup
```
## License
[![ansible-yunohost Copyright 2021 Lydra](https://www.gnu.org/graphics/gplv3-with-text-136x68.png)](https://choosealicense.com/licenses/gpl-3.0/)
**ansible-yunohost** is maintained by [Lydra](https://lydra.fr/) and released under the GPL3 license.
---
#-----------------------------------------------------------------------------#
# ansible-yunohost allows to deploy Yunohost using Ansible #
# Copyright 2021-2021 Lydra https://www.lydra.fr/ #
# Copyright 2021-present Lydra https://www.lydra.fr/ #
# #
# this program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
......@@ -36,20 +36,7 @@ ynh_users: null
# lastname: Doe
# mail_domain: domain.tld
# Do not touch this variable
# Just to have dict default value
ynh_smtp_relay:
value: null
# SMTP custom settings (Only override if you need a SMTP relay)
# Example:
# ynh_smtp_relay:
# host: smtp.domain.tld
# port: "25"
# user: user1
# password: Pa$$w0rd
# The list of Yunohost apps.
# The list of Yunohost apps.
ynh_apps: null
# - label: Tiny Tiny RSS
# link: ttrss
......@@ -62,11 +49,3 @@ ynh_apps: null
# type: script
# owner: ttrss # Only provide if different from app name
# group: ttrss # Only provide if different from www-data
# Autoupdate Yunohost and its apps
ynh_autoupdate:
scheduled: False
# special_time: "daily" #Choices are [annually,daily,hourly,monthly,reboot,weekly,yearly]
# apps: True
# system: True
# dest_script: "/usr/local/bin/"
---
galaxy_info:
role_name: ynh_setup
author: lydra
description: Install Yunohost with Ansible
license: GPL-v3
min_ansible_version: 2.10
github_branch: main
platforms:
- name: Debian
versions:
- buster
galaxy_tags:
- yunohost
- cloud
- web
dependencies: []
---
#-----------------------------------------------------------------------------#
# ansible-yunohost allows to deploy Yunohost using Ansible #
# Copyright 2021-2021 Lydra https://www.lydra.fr/ #
# Copyright 2021-present Lydra https://www.lydra.fr/ #
# #
# this program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
......@@ -24,6 +24,8 @@
--label "{{ ynh_app.label }}" \
--args "{% for key, value in ynh_app.args.items() %}{{ key }}={{ value }}{% if not loop.last %}&{% endif %}{% endfor %}"
changed_when: False
tags:
- apps
# Post-installation part
- name: Create post-install template
......@@ -35,6 +37,8 @@
mode: "{{ (item.type == 'script') | ternary('740', '660') }}"
loop: "{{ ynh_app.post_install|default([]) }}"
when: ynh_app.post_install
tags:
- apps
- name: Launch post-install script
ansible.builtin.command: "{{ ynh_app_post_install.dest }}"
......@@ -44,6 +48,8 @@
loop_control:
loop_var: ynh_app_post_install
when: ynh_app_post_install.type == "script"
tags:
- apps
- name: Remove script after execution
ansible.builtin.file:
......@@ -53,3 +59,5 @@
loop_control:
loop_var: ynh_app_post_install
when: ynh_app_post_install.type == "script"
tags:
- apps
---
#-----------------------------------------------------------------------------#
# ansible-yunohost allows to deploy Yunohost using Ansible #
# Copyright 2021-2021 Lydra https://www.lydra.fr/ #
# Copyright 2021-present Lydra https://www.lydra.fr/ #
# #
# this program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
......@@ -22,9 +22,13 @@
ansible.builtin.command: yunohost app map --output-as json
register: ynh_installed_apps_raw
changed_when: False
tags:
- apps
- name: Format json of apps
ansible.builtin.set_fact: ynh_installed_apps="{{ ynh_installed_apps_raw.stdout | from_json }}"
tags:
- apps
- name: Install yunohost apps and perform post-install
ansible.builtin.include_tasks: app.yml
......@@ -32,3 +36,6 @@
loop_control:
loop_var: ynh_app
when: ynh_app.label not in ynh_installed_apps.values()
tags:
- apps
---
#-----------------------------------------------------------------------------#
# ansible-yunohost allows to deploy Yunohost using Ansible #
# Copyright 2021-2021 Lydra https://www.lydra.fr/ #
# Copyright 2021-present Lydra https://www.lydra.fr/ #
# #
# this program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
......@@ -22,11 +22,20 @@
ansible.builtin.command: yunohost domain list --output-as json
register: ynh_installed_domains_raw
changed_when: False
tags:
- yunohost
- domains
- name: Format json of domains
ansible.builtin.set_fact: ynh_installed_domains="{{ ynh_installed_domains_raw.stdout | from_json }}"
tags:
- yunohost
- domains
- name: Create domains
ansible.builtin.command: yunohost domain add {{ item }}
with_items: "{{ ynh_extra_domains }}"
when: item not in ynh_installed_domains.domains
tags:
- yunohost
- domains
---
#-----------------------------------------------------------------------------#
# ansible-yunohost allows to deploy Yunohost using Ansible #
# Copyright 2021-2021 Lydra https://www.lydra.fr/ #
# Copyright 2021-present Lydra https://www.lydra.fr/ #
# #
# this program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
......@@ -24,10 +24,49 @@
- git
- dialog
state: present
tags:
- pkg
- linux
- yunohost
- name: Create apps and config directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: 0770
loop:
- "{{ ynh_symlink.appdata_dir }}"
- "{{ ynh_symlink.conf_dir }}"
tags:
- linux
- yunohost
when: ynh_symlink.enabled
- name: Create symbolic link for Yunohost apps data directory
ansible.builtin.file:
src: /var/www/
dest: "{{ ynh_symlink.appdata_dir }}/www_symlink"
state: link
tags:
- linux
- yunohost
when: ynh_symlink.enabled
- name: Create symbolic link for Yunohost configuration directory
ansible.builtin.file:
src: /etc/yunohost/
dest: "{{ ynh_symlink.conf_dir }}/yunohost_symlink"
state: link
tags:
- linux
- yunohost
when: ynh_symlink.enabled
- name: Test if Yunohost is already installed
ansible.builtin.stat: path=/etc/yunohost/installed
register: ynh_file_install
tags:
- yunohost
- name: Download Yunohost install script
ansible.builtin.get_url:
......@@ -35,10 +74,14 @@
dest: /tmp/install_yunohost.sh
mode: 700
when: not ynh_file_install.stat.exists
tags:
- yunohost
- name: Launch Yunohost install script
ansible.builtin.command: /tmp/install_yunohost.sh -a
when: not ynh_file_install.stat.exists
tags:
- yunohost
- name: Launch Yunohost postinstall
ansible.builtin.command:
......@@ -47,32 +90,32 @@
--password "{{ ynh_admin_password }}" \
{% if ynh_ignore_dyndns_server %} --ignore-dyndns {% endif %}
when: not ynh_file_install.stat.exists
tags:
- yunohost
- domains
- name: Create extra domains
ansible.builtin.include_tasks: domains.yml
when: ynh_extra_domains
tags:
- yunohost
- domains
- name: Run first Yunohost diagnosis
ansible.builtin.command: yunohost diagnosis run
when: not ynh_file_install.stat.exists
tags:
- yunohost
- name: Install domain certificates
ansible.builtin.command: yunohost domain cert-install
changed_when: False
- name: Configure SMTP relay
ansible.builtin.include_tasks: smtp_relay.yml
loop: "{{ ynh_smtp_relay | dict2items }}"
when: item.value
tags:
- yunohost
- name: Add Yunohost users
ansible.builtin.include_tasks: users.yml
when: ynh_users
- name: Install Yunohost apps
ansible.builtin.include_tasks: apps.yml
when: ynh_apps
- name: Configures Yunohost autoupdate
ansible.builtin.include_tasks: autoupdate.yml
when: ynh_autoupdate.scheduled
tags:
- yunohost
- users
---
#-----------------------------------------------------------------------------#
# ansible-yunohost allows to deploy Yunohost using Ansible #
# Copyright 2021-2021 Lydra https://www.lydra.fr/ #
# Copyright 2021-present Lydra https://www.lydra.fr/ #
# #
# this program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
......@@ -22,9 +22,15 @@
ansible.builtin.command: yunohost user list --output-as json
register: ynh_registered_users_raw
changed_when: False
tags:
- yunohost
- users
- name: Format json of users
ansible.builtin.set_fact: ynh_registered_users="{{ ynh_registered_users_raw.stdout | from_json }}"
tags:
- yunohost
- users
- name: Create missing Yunohost users
ansible.builtin.command:
......@@ -35,3 +41,6 @@
-p "{{ item.pass }}"
loop: "{{ ynh_users }}"
when: item.name not in ynh_registered_users.users.keys()
tags:
- yunohost
- users
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment