From 5bc931dfe648671bbfb123eb796685ca8e9fa39f Mon Sep 17 00:00:00 2001 From: Arthur BOUDREAULT <boudreaultarthur@ik.me> Date: Tue, 2 Nov 2021 15:40:54 +0100 Subject: [PATCH] feat: execute if script ok --- defaults/main.yml | 8 ++++++++ tasks/app.yml | 23 ++++++++++++----------- tasks/apps.yml | 23 +++-------------------- tasks/main.yml | 6 +----- 4 files changed, 24 insertions(+), 36 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 14b42ca..f5b8de4 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 38694ff..d45290d 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 e156a91..83ffc62 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 42307bb..75c3904 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 -- GitLab