--- - name: Install the cran repository key apt_key: id=E084DAB9 keyserver=keyserver.ubuntu.com state=present register: update_apt_cache when: r_install_cran_repo tags: - r_software - r_repo - name: Install the cran repository definition apt_repository: repo='deb http://cran.rstudio.com/bin/linux/ubuntu {{ ansible_distribution_release }}/' state=present register: update_apt_cache when: r_install_cran_repo tags: - r_software - r_repo - name: Install the cran repository definition apt_repository: repo='deb {{ r_cran_mirror_site }}/bin/linux/ubuntu {{ ansible_distribution_release }}/' state=absent register: update_apt_cache when: not r_install_cran_repo tags: - r_software - r_repo - name: Update the apt cache if needed apt: update_cache=yes when: ( update_apt_cache | changed ) tags: - r_software - r_repo - name: Install the R base packages apt: pkg={{ item }} state={{ r_packages_state }} with_items: r_base_packages_list tags: - r_software - r_pkg - name: Install the R plugins from the ubuntu repo apt: pkg={{ item }} state={{ r_packages_state }} with_items: r_plugins_packages_list tags: - r_software - r_pkg - name: Install R plugins from the cran binaries repo 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 tags: - r_software - r_pkg