ansible-roles/R/tasks/main.yml

77 lines
4.4 KiB
YAML
Raw Normal View History

---
- 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: Install a specific version of the R base package
apt: pkg={{ item }} state={{ r_packages_state }}
with_items: r_base_packages_list
tags: [ 'r_software', 'r_pkg' ]
- name: Install the R additional modules from the deb repo
apt: pkg={{ item }} state={{ r_packages_state }}
with_items: r_plugins_packages_list
when: r_plugins_from_deb
tags: [ 'r_software', 'r_pkg' ]
- name: Install some packages needed by R plugins when installed from source, if needed
apt: pkg={{ item }} state={{ r_packages_state }} update_cache=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: 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', '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
tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_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
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: 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' ]