From 39a12b293651ae809bdd0d754a02611d690ef4de Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 3 Dec 2015 17:16:44 +0100 Subject: [PATCH] library/roles/R/tasks/main.yml: better test for the task that installs specific versions of the R library packages. library/roles/R/tasks/main.yml: implement packages removal. d4science-ghn-cluster/roles/dataminer_app/tasks/main.yml: Cleanup the pom dependencies mess. --- R/defaults/main.yml | 2 +- R/tasks/main.yml | 35 ++++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/R/defaults/main.yml b/R/defaults/main.yml index e43badd5..f016fe69 100644 --- a/R/defaults/main.yml +++ b/R/defaults/main.yml @@ -88,6 +88,6 @@ r_plugins_list_to_install: # - { plugin_name: 'RFigisGeo', github_user: 'openfigis' } # - { plugin_name: 'rsdmx', github_user: 'opensdmx' } -# Plugins removal not yet implemented +# #r_plugins_list_to_remove: diff --git a/R/tasks/main.yml b/R/tasks/main.yml index 44820d51..9399040d 100644 --- a/R/tasks/main.yml +++ b/R/tasks/main.yml @@ -24,28 +24,28 @@ when: r_needs_additional_distro_pkgs tags: [ 'r_software', 'r_pkg' ] -- name: Ensure that the R plugin sources directory exists +- name: Ensure that the R packages sources directory exists file: dest={{ r_source_plugins_dest_dir }} state=directory owner=root group=root when: r_plugins_from_sources is defined - tags: [ 'r_software', 'r_pkg', 'r_plugins' ] + tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ] -- name: Get the R plugin sources that need to be installed +- name: Get the R packages sources that need to be installed get_url: url={{ item.url }} dest={{ r_source_plugins_dest_dir }} with_items: r_plugins_from_sources when: r_plugins_from_sources is defined - tags: [ 'r_software', 'r_pkg', 'r_plugins' ] + tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ] -- name: Install R plugins from the cran sources, specific versions +- name: Install R packages from the cran sources, specific versions command: > - Rscript --slave --no-save --no-restore-history -e "if (! ('{{ item.name }}' %in% installed.packages()[,'Package'])) { install.packages('{{ r_source_plugins_dest_dir }}/{{ item.source }}', repos = NULL, type='source'); print('Added'); } else { print('Already Installed'); }" + Rscript --slave --no-save --no-restore-history -e "if (! ('{{ item.name }}' %in% installed.packages()[,'Package'])) { install.packages('{{ r_source_plugins_dest_dir }}/{{ item.source }}', repos = NULL, type='source'); print('Added'); } else if (packageVersion('{{ item.name }}') != '{{ item.version }}') { install.packages('{{ r_source_plugins_dest_dir }}/{{ item.source }}', repos = NULL, type='source'); print('Added'); } else { print('Already Installed'); }" register: install_s_plugins_result failed_when: "install_s_plugins_result.rc != 0 or 'had non-zero exit status' in install_s_plugins_result.stderr" - changed_when: "'Added' in install_s_plugins_result.stdout" + changed_when: '"Added" in install_s_plugins_result.stdout' with_items: r_plugins_from_sources when: r_plugins_install_specific_source - tags: [ 'r_software', 'r_pkg', 'r_plugins' ] + tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ] -- name: Install R plugins from the cran sources repo, latest version +- name: Install R packages from the cran sources repo, latest version command: > Rscript --slave --no-save --no-restore-history -e "if (! ('{{ item }}' %in% installed.packages()[,'Package'])) { install.packages(pkgs='{{ item }}', repos=c('{{ r_cran_mirror_site }}/')); print('Added'); } else { print('Already installed'); }" register: install_plugins_result @@ -55,13 +55,22 @@ when: r_plugins_install_latest_source tags: [ 'r_software', 'r_pkg', 'r_plugins' ] -- name: Install R plugins from github +- name: Install R packages from github command: > Rscript --slave --no-save --no-restore-history -e "if (! ('{{ item.plugin_name }}' %in% installed.packages()[,'Package'])) { require(devtools); require(methods) ; options(repos='{{ r_cran_mirror_site }}/') ; install_github('{{ item.plugin_name }}', '{{ item.github_user }}'); print('Added'); } else { print('Already Installed'); }" - register: install_s_plugins_result - failed_when: "install_s_plugins_result.rc != 0 or 'had non-zero exit status' in install_s_plugins_result.stderr" - changed_when: "'Added' in install_s_plugins_result.stdout" + register: install_github_plugins_result + failed_when: "install_github_plugins_result.rc != 0 or 'had non-zero exit status' in install_s_plugins_result.stderr" + changed_when: "'Added' in install_github_plugins_result.stdout" with_items: r_plugins_from_github when: r_plugins_from_github is defined tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github' ] +- name: Remove R unwanted packages + command: > + Rscript --slave --no-save --no-restore-history -e "if (! ('{{ item }}' %in% installed.packages()[,'Package'])) { print('Not installed'); } else { remove.packages(pkgs='{{ item }}'); print('Removed'); }" + register: remove_plugins_result + failed_when: remove_plugins_result.rc != 0 + changed_when: "'Removed' in remove_plugins_result.stdout" + with_items: r_plugins_list_to_remove + when: r_plugins_list_to_remove is defined + tags: [ 'r_software', 'r_pkg', 'r_plugins' ]