diff --git a/defaults/main.yml b/defaults/main.yml index 14b42ca5c4da019ceec7727e61c3aa6db17721a9..f5b8de422badbad0f835751e97ecbd0b5fd7f32f 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -56,3 +56,11 @@ ynh_apps: null # args: # domain: domain.tld # path: /ttrss + # post_install: + # - src: "templates/file.sh.j2" + # dest: "/tmp/script.sh" + # type: script + # owner: tinyrss + # group: www-data + # mode: "0770" + diff --git a/tasks/app.yml b/tasks/app.yml index 38694ffaba0fc239ea3b08d965192460029e8e20..d45290d96f3a1d06854f831c792f34627e26c8c4 100644 --- a/tasks/app.yml +++ b/tasks/app.yml @@ -19,20 +19,14 @@ #-----------------------------------------------------------------------------# # Installation part - -- name: debug - debug: - msg: "Voici le résultat :{{ ynh_app }}" - tags: apps - -- name: Install yunohost apps (you are inside app.yml) +- 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 - tags: apps -- name: Transfer template to node (can be a config file or a script) #loop item.post-install +# Post-installation part +- name: Transfer template to node (can be a config file or a script) ansible.builtin.template: src: "{{ item.src }}" dest: "{{ item.dest }}" @@ -40,5 +34,12 @@ group: "{{ item.group }}" mode: "{{ item.mode }}" loop: "{{ ynh_app.post_install }}" - when: ynh_app.post_install is defined - tags: apps + +- name: Execute script if file type is a script + ansible.builtin.command: "{{ pst_install.dest }}" + args: + chdir: /tmp/ + loop: "{{ ynh_app.post_install }}" + loop_control: + loop_var: pst_install + when: pst_install.type == "script" diff --git a/tasks/apps.yml b/tasks/apps.yml index e156a91e2f38fc7bf6ce3263ac9e06a5081edc2b..83ffc62e379d71d0b3140d481f8623878bf558d0 100644 --- a/tasks/apps.yml +++ b/tasks/apps.yml @@ -18,37 +18,20 @@ # # #-----------------------------------------------------------------------------# -- name: List currently installed apps (you are inside apps.yml) +- name: List currently installed apps ansible.builtin.command: yunohost app map --output-as json register: ynh_installed_apps_raw changed_when: False tags: apps -- name: Format json of apps (you are inside apps.yml) +- 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 (you are inside apps.yml) +- 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() tags: apps - -# - name: debug (you are in apps.yml) -# debug: -# msg: "Voici le résultat :{{ item.post_install.0.src }}" -# loop: "{{ ynh_apps.post_install.key }}" -# when: ynh_apps.post_install is defined -# tags: apps -## post-install: - -# boucler sur les apps et inclure ce fichier de tasks -# install app puis post install puis app puis post-install - -# quand dans fichier apps -# command remplacée par include app.yml -# command à l'intérieur du fichier de tache app -# dans app il faudra boucler sur app pour -# item.post_installl diff --git a/tasks/main.yml b/tasks/main.yml index 42307bb957b8da8b3253dfab34c9449c2b6ab508..75c3904f8fb73e7e16b19a441f179f8d71b4e7fb 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -69,12 +69,8 @@ ansible.builtin.include_tasks: users.yml when: ynh_users -- name: Install Yunohost apps (you are in main.yml) +- name: Install Yunohost apps ansible.builtin.include_tasks: apps.yml when: ynh_apps tags: apps -# - name: Launch post-install for apps -# ansible.builtin.include_tasks: postinstall.yml -# loop: "{{ post_install | dict2items }}" -# when: post_install