From 2ce227b4a6c90e8706cb27ac18fad1dbe5ea086f Mon Sep 17 00:00:00 2001
From: Andrea Dell'Amico <adellam@isti.cnr.it>
Date: Mon, 10 Oct 2016 17:57:48 +0200
Subject: [PATCH] library/isti_vars/r-packages.yml: Remove some redundant
 variables. library/roles/R/tasks/r-installation.yml: Try better checks to
 reduce the installation time.

---
 R/defaults/main.yml        | 47 ++++++++++++++++++--------------------
 R/tasks/r-installation.yml |  9 ++------
 2 files changed, 24 insertions(+), 32 deletions(-)

diff --git a/R/defaults/main.yml b/R/defaults/main.yml
index 3fb6640..a9a3abb 100644
--- a/R/defaults/main.yml
+++ b/R/defaults/main.yml
@@ -19,10 +19,7 @@ r_base_specific_version: False
 r_base_pkg_version: 2.14.1
 r_packages_main_state: present
 r_packages_state: '{{ r_packages_main_state }}'
-r_needs_additional_distro_pkgs: False
 r_plugins_from_deb: True
-r_plugins_install_latest_source: True
-r_plugins_install_specific_source: True
 r_packages_cleanup: False
 
 r_source_plugins_dest_dir: /var/cache/R
@@ -66,28 +63,28 @@ r_plugins_packages_list:
   - r-cran-spatial
   - r-cran-survival
 
-r_plugins_list_to_install:
-  - { name: 'R2WinBUGS', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'R2jags', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'bayesmix', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'coda', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'rjags', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'runjags', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'base', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'compiler', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'datasets', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'grDevices', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'graphics', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'grid', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'methods', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'parallel', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'reshape', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'splines', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'stats', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'stats4', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'tcltk', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'tools', repo: '{{ r_cran_mirror_site }}' }
-  - { name: 'utils', repo: '{{ r_cran_mirror_site }}' }
+# r_plugins_list_to_install:
+#   - { name: 'R2WinBUGS', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'R2jags', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'bayesmix', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'coda', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'rjags', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'runjags', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'base', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'compiler', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'datasets', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'grDevices', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'graphics', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'grid', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'methods', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'parallel', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'reshape', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'splines', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'stats', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'stats4', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'tcltk', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'tools', repo: '{{ r_cran_mirror_site }}' }
+#   - { name: 'utils', repo: '{{ r_cran_mirror_site }}' }
 
 # r_plugins_from_sources:
 #   - { name: 'plyr', version: '1.7.1', source: 'plyr_1.7.1.tar.gz', url: 'http://cran.r-project.org/src/contrib/Archive/plyr/plyr_1.7.1.tar.gz' }
diff --git a/R/tasks/r-installation.yml b/R/tasks/r-installation.yml
index 1340978..4db8fd3 100644
--- a/R/tasks/r-installation.yml
+++ b/R/tasks/r-installation.yml
@@ -40,7 +40,6 @@
 - name: Install some packages needed by R packages when installed from source
   apt: pkg={{ item }} state={{ r_packages_state }} update_cache=yes force=yes
   with_items: '{{ r_distribution_required_packages | default([]) }}'
-  when: r_needs_additional_distro_pkgs
   tags: [ 'r_software', 'r_pkg', 'r_deps' ]
   
 - name: Ensure that the R packages sources directory exists
@@ -55,14 +54,12 @@
   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 | default([]) }}'
-  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
   get_url: url={{ item.url }} dest={{ r_source_plugins_dest_dir }}
   with_items: '{{ r_plugins_from_sources | default([]) }}'
-  when: r_plugins_install_specific_source
   tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ]
   
 - name: Install R packages from the cran sources, specific versions. First round
@@ -72,7 +69,6 @@
   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 | default([]) }}'
-  when: r_plugins_install_specific_source
   ignore_errors: True
   tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ]
 
@@ -83,7 +79,7 @@
   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 | default([]) }}'
-  when: r_plugins_install_specific_source
+  when: ( install_s_plugins_result | failed )
   tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ]
 
 - name: Install R packages from the cran sources repo or from an alternative repository, latest available version. Second try
@@ -93,7 +89,7 @@
   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 | default([]) }}'
-  when: r_plugins_install_latest_source
+  when: ( install_plugins_result | failed )
   tags: [ 'r_software', 'r_pkg', 'r_plugins' ]
 
 - name: Install R packages from github
@@ -103,7 +99,6 @@
   failed_when: "install_github_plugins_result.rc != 0 or 'had non-zero exit status' in install_github_plugins_result.stderr"
   changed_when: "'Added' in install_github_plugins_result.stdout"
   with_items: '{{ r_plugins_from_github | default([]) }}'
-  when: r_plugins_from_github is defined
   tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github' ]
 
 - name: Remove R unwanted packages