From 7e3ad01c3532b8c266ba67d8e983d60c519a51a5 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Tue, 1 Mar 2016 16:17:54 +0100 Subject: [PATCH] library/roles/R/tasks/r-installation.yml: Try to avoid a double run of the R packages install task. --- R/tasks/r-installation.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/R/tasks/r-installation.yml b/R/tasks/r-installation.yml index d928df9..1b7f3ab 100644 --- a/R/tasks/r-installation.yml +++ b/R/tasks/r-installation.yml @@ -48,7 +48,7 @@ when: r_plugins_from_sources is defined tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ] -- name: Install R packages from the cran sources repo, latest available version +- name: Install R packages from the cran sources repo, latest available version. First try 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 @@ -56,6 +56,7 @@ changed_when: "'Added' in install_plugins_result.stdout" with_items: r_plugins_list_to_install when: r_plugins_install_latest_source + ignore_errors: True tags: [ 'r_software', 'r_pkg', 'r_plugins' ] - name: Get the R packages sources that need to be installed @@ -72,6 +73,7 @@ changed_when: '"Added" in install_s_plugins_result.stdout' with_items: r_plugins_from_sources when: r_plugins_install_specific_source + register: r_packages_specific_source ignore_errors: True tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ] @@ -82,9 +84,23 @@ 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' with_items: r_plugins_from_sources - when: r_plugins_install_specific_source + when: + - r_plugins_install_specific_source + - "install_s_plugins_result.rc != 0 or 'had non-zero exit status' in install_s_plugins_result.stderr" tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ] +- name: Install R packages from the cran sources repo, latest available version. Second try + 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 + failed_when: "install_plugins_result.rc != 0 or 'had non-zero exit status' in install_plugins_result.stderr" + changed_when: "'Added' in install_plugins_result.stdout" + with_items: r_plugins_list_to_install + when: + - r_plugins_install_latest_source + - "install_plugins_result.rc != 0 or 'had non-zero exit status' in install_plugins_result.stderr" + tags: [ 'r_software', 'r_pkg', 'r_plugins' ] + - 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'); }"