forked from ISTI-ansible-roles/ansible-roles
d4science-ghn-cluster: New dataminer version and R packages list.
library/roles/R: A script that remove the old R installation, on demand.
This commit is contained in:
parent
c8645263ce
commit
4662445ea7
|
@ -21,6 +21,7 @@ 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
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Put the base packages to unhold
|
||||
for package in r-base r-base-core r-base-dev r-base-html r-cran-boot r-cran-class r-cran-cluster r-cran-codetools r-cran-foreign r-cran-kernsmooth r-cran-lattice r-cran-mass r-cran-matrix r-cran-mgcv r-cran-nlme r-cran-nnet r-cran-rpart r-cran-spatial r-cran-survival r-doc-html r-recommended ; do apt-mark unhold $package; done
|
||||
|
||||
# Remove the old r packages
|
||||
apt-get purge r-base-* r-cran-* -y
|
||||
|
||||
# Remove the CRAN packages
|
||||
rm -fr /usr/lib/R /usr/local/lib/R
|
||||
rm -fr /var/cache/R/*
|
||||
|
||||
exit 0
|
108
R/tasks/main.yml
108
R/tasks/main.yml
|
@ -1,106 +1,4 @@
|
|||
---
|
||||
- name: Manage the cran repository key
|
||||
apt_key: id=E084DAB9 keyserver=keyserver.ubuntu.com state={{ r_install_cran_repo }}
|
||||
tags: [ 'r_software', 'r_repo' ]
|
||||
|
||||
- name: Manage the cran repository definition
|
||||
apt_repository: repo='deb http://cran.rstudio.com/bin/linux/ubuntu {{ ansible_distribution_release }}/' state={{ r_install_cran_repo }} update_cache=yes
|
||||
tags: [ 'r_software', 'r_repo' ]
|
||||
|
||||
- name: Remove the hold state from the debian R packages
|
||||
shell: apt-mark unhold {{ item }}
|
||||
with_items: r_base_packages_hold_list
|
||||
when: r_base_packages_hold_list is defined
|
||||
ignore_errors: True
|
||||
tags: [ 'r_software', 'r_pkg', 'r_pkg_hold' ]
|
||||
|
||||
- name: Install the R base packages.
|
||||
apt: pkg={{ item }} state={{ r_packages_main_state }} force=yes
|
||||
with_items: r_base_packages_list
|
||||
tags: [ 'r_software', 'r_pkg' ]
|
||||
|
||||
- name: When we install specific R deb packages, put them on hold
|
||||
shell: apt-mark hold {{ item }}
|
||||
with_items: r_base_packages_hold_list
|
||||
when: r_base_specific_version
|
||||
ignore_errors: True
|
||||
tags: [ 'r_software', 'r_pkg', 'r_pkg_hold' ]
|
||||
|
||||
- name: Install the R additional modules from the deb repo
|
||||
apt: pkg={{ item }} state={{ r_packages_state }} force=yes
|
||||
with_items: r_plugins_packages_list
|
||||
when: r_plugins_from_deb
|
||||
tags: [ 'r_software', 'r_pkg' ]
|
||||
|
||||
- name: Configure the default CRAN mirror
|
||||
template: src=Rprofile.site.j2 dest=/etc/R/Rprofile.site owner=root group=root mode=0444
|
||||
when: r_install_cran_repo == 'present'
|
||||
tags: [ 'r_software', 'r_profile', 'r_pkg' ]
|
||||
|
||||
- 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
|
||||
when: r_needs_additional_distro_pkgs
|
||||
tags: [ 'r_software', 'r_pkg' ]
|
||||
|
||||
- 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', 'r_plugins_version' ]
|
||||
|
||||
- name: Install R packages from the cran sources repo, latest available 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
|
||||
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
|
||||
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
|
||||
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
|
||||
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 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'
|
||||
with_items: r_plugins_from_sources
|
||||
when: r_plugins_install_specific_source
|
||||
ignore_errors: True
|
||||
tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ]
|
||||
|
||||
- name: Install R packages from the cran sources, specific versions. Second round, to avoid circular dependencies
|
||||
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 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'
|
||||
with_items: r_plugins_from_sources
|
||||
when: r_plugins_install_specific_source
|
||||
tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ]
|
||||
|
||||
- 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_github_plugins_result
|
||||
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
|
||||
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' ]
|
||||
- include: r-packages_cleanup.yml
|
||||
when: r_packages_cleanup
|
||||
- include: r-installation.yml
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
---
|
||||
- name: Manage the cran repository key
|
||||
apt_key: id=E084DAB9 keyserver=keyserver.ubuntu.com state={{ r_install_cran_repo }}
|
||||
tags: [ 'r_software', 'r_repo' ]
|
||||
|
||||
- name: Manage the cran repository definition
|
||||
apt_repository: repo='deb http://cran.rstudio.com/bin/linux/ubuntu {{ ansible_distribution_release }}/' state={{ r_install_cran_repo }} update_cache=yes
|
||||
tags: [ 'r_software', 'r_repo' ]
|
||||
|
||||
- name: Remove the hold state from the debian R packages
|
||||
shell: apt-mark unhold {{ item }}
|
||||
with_items: r_base_packages_hold_list
|
||||
when: r_base_packages_hold_list is defined
|
||||
ignore_errors: True
|
||||
tags: [ 'r_software', 'r_pkg', 'r_pkg_hold' ]
|
||||
|
||||
- name: Install the R base packages.
|
||||
apt: pkg={{ item }} state={{ r_packages_main_state }} force=yes
|
||||
with_items: r_base_packages_list
|
||||
tags: [ 'r_software', 'r_pkg' ]
|
||||
|
||||
- name: When we install specific R deb packages, put them on hold
|
||||
shell: apt-mark hold {{ item }}
|
||||
with_items: r_base_packages_hold_list
|
||||
when: r_base_specific_version
|
||||
ignore_errors: True
|
||||
tags: [ 'r_software', 'r_pkg', 'r_pkg_hold' ]
|
||||
|
||||
- name: Install the R additional modules from the deb repo
|
||||
apt: pkg={{ item }} state={{ r_packages_state }} force=yes
|
||||
with_items: r_plugins_packages_list
|
||||
when: r_plugins_from_deb
|
||||
tags: [ 'r_software', 'r_pkg' ]
|
||||
|
||||
- name: Configure the default CRAN mirror
|
||||
template: src=Rprofile.site.j2 dest=/etc/R/Rprofile.site owner=root group=root mode=0444
|
||||
when: r_install_cran_repo == 'present'
|
||||
tags: [ 'r_software', 'r_profile', 'r_pkg' ]
|
||||
|
||||
- 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
|
||||
when: r_needs_additional_distro_pkgs
|
||||
tags: [ 'r_software', 'r_pkg' ]
|
||||
|
||||
- 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', 'r_plugins_version' ]
|
||||
|
||||
- name: Install R packages from the cran sources repo, latest available 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
|
||||
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
|
||||
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
|
||||
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
|
||||
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 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'
|
||||
with_items: r_plugins_from_sources
|
||||
when: r_plugins_install_specific_source
|
||||
ignore_errors: True
|
||||
tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ]
|
||||
|
||||
- name: Install R packages from the cran sources, specific versions. Second round, to avoid circular dependencies
|
||||
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 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'
|
||||
with_items: r_plugins_from_sources
|
||||
when: r_plugins_install_specific_source
|
||||
tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_version' ]
|
||||
|
||||
- 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_github_plugins_result
|
||||
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
|
||||
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' ]
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
- name: Install the script that cleans up the R deb and cran packages
|
||||
copy: src=r_packages_cleanup.sh dest=/usr/local/bin/r_packages_cleanup owner=root group=root mode=0500
|
||||
tags: [ 'r_software', 'r_pkgs', 'r_cleanup' ]
|
||||
|
||||
- name: Remove all the old R deb and cran packages. Otherwise the upgrade will fail miserably
|
||||
shell: /usr/local/bin/r_packages_cleanup
|
||||
tags: [ 'r_software', 'r_pkgs', 'r_cleanup' ]
|
Loading…
Reference in New Issue