Merge branch '32-feat-add-app-post_install' into 'main'
Resolve "feat: add app post_install" Closes #32 See merge request lydra/yunohost/ansible-yunohost!16
This commit is contained in:
commit
2e8dacdd1c
5 changed files with 116 additions and 8 deletions
25
README-FR.md
25
README-FR.md
|
@ -95,19 +95,42 @@ ynh_apps:
|
|||
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 :
|
||||
#### Concernant les arguments :
|
||||
- `domain` est indispensable. Il faut choisir un des domaines de son instance Yunohost.
|
||||
- `path` est indispensable. 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.
|
||||
|
|
25
README.md
25
README.md
|
@ -95,19 +95,42 @@ ynh_apps:
|
|||
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:
|
||||
#### 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.
|
||||
|
|
|
@ -56,3 +56,10 @@ ynh_apps: null
|
|||
# args:
|
||||
# domain: domain.tld
|
||||
# path: /ttrss
|
||||
# post_install:
|
||||
# - src: "templates/file.sh.j2"
|
||||
# dest: "/tmp/script.sh"
|
||||
# type: script
|
||||
# owner: ttrss # Only provide if different from app name
|
||||
# group: ttrss # Only provide if different from www-data
|
||||
|
||||
|
|
55
tasks/app.yml
Normal file
55
tasks/app.yml
Normal file
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
#-----------------------------------------------------------------------------#
|
||||
# ansible-yunohost allows to deploy Yunohost using Ansible #
|
||||
# Copyright 2021-2021 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 #
|
||||
# the Free Software Foundation, either version 3 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# this program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
# Installation part
|
||||
- name: Install yunohost apps
|
||||
ansible.builtin.command: yunohost app install {{ ynh_app.link }} \
|
||||
--label "{{ ynh_app.label }}" \
|
||||
--args "{% for key, value in ynh_app.args.items() %}{{ key }}={{ value }}{% if not loop.last %}&{% endif %}{% endfor %}"
|
||||
changed_when: False
|
||||
|
||||
# Post-installation part
|
||||
- name: Create post-install template
|
||||
ansible.builtin.template:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ item.dest }}"
|
||||
owner: "{{ item.owner | default(ynh_app.link) }}"
|
||||
group: "{{ item.group | default('www-data') }}"
|
||||
mode: "{{ (item.type == 'script') | ternary('740', '660') }}"
|
||||
loop: "{{ ynh_app.post_install|default([]) }}"
|
||||
when: ynh_app.post_install
|
||||
|
||||
- name: Launch post-install script
|
||||
ansible.builtin.command: "{{ ynh_app_post_install.dest }}"
|
||||
args:
|
||||
chdir: /tmp/
|
||||
loop: "{{ ynh_app.post_install|default([]) }}"
|
||||
loop_control:
|
||||
loop_var: ynh_app_post_install
|
||||
when: ynh_app_post_install.type == "script"
|
||||
|
||||
- name: Remove script after execution
|
||||
ansible.builtin.file:
|
||||
path: "{{ ynh_app_post_install.dest }}"
|
||||
state: absent
|
||||
loop: "{{ ynh_app.post_install|default([]) }}"
|
||||
loop_control:
|
||||
loop_var: ynh_app_post_install
|
||||
when: ynh_app_post_install.type == "script"
|
|
@ -26,9 +26,9 @@
|
|||
- name: Format json of apps
|
||||
ansible.builtin.set_fact: ynh_installed_apps="{{ ynh_installed_apps_raw.stdout | from_json }}"
|
||||
|
||||
- name: Install yunohost apps
|
||||
ansible.builtin.command: yunohost app install {{ item.link }} \
|
||||
--label "{{ item.label }}" \
|
||||
--args "{% for key, value in item.args.items() %}{{ key }}={{ value }}{% if not loop.last %}&{% endif %}{% endfor %}"
|
||||
with_items: "{{ ynh_apps }}"
|
||||
when: item.label not in ynh_installed_apps.values()
|
||||
- name: Install yunohost apps and perform post-install
|
||||
ansible.builtin.include_tasks: app.yml
|
||||
loop: "{{ ynh_apps }}"
|
||||
loop_control:
|
||||
loop_var: ynh_app
|
||||
when: ynh_app.label not in ynh_installed_apps.values()
|
||||
|
|
Loading…
Reference in a new issue