Ansible role that installs R itself, R packages (from CRAN, archived and remote repos) and associated tools.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
3.4 KiB

# use force=TRUE to allow upgrading (overwriting) an existing Hugo executable
# note: install_hugo() seems to prefer the extended version of Hugo (which supports Sass/SCSS). Good!
- name: "Install Hugo v{{ hugo_version }}"
ansible.builtin.command: >
Rscript --slave --no-save --no-restore-history -e
"blogdown::install_hugo(force = TRUE, version = '{{ hugo_version }}')"
# You are recommended to set options(blogdown.hugo.version = "<version>") in the .Rprofile file in your website project. See the blogdown book for more info on .Rprofile:
# The idea being, of course, to allow each website project to use its own Hugo version
# thus avoiding sudden breaking changes due to updated Hugo version.
# I think I will also set a hugo version globally (feel free to set .Rprofile locally per-project, those local settings should override the global anyway)
- name: "Add options(blogdown.hugo.version = {{ hugo_version }}) to global"
path: "{{ R_directory }}/{{ R_version }}/lib/R/etc/"
insertafter: "blogdown.hugo.dir"
line: "options(blogdown.hugo.version = \"{{ hugo_version }}\")"
# wordcloud2 package requires PhantomJS to produce anything other than HTML
# knitr suggests installing it with webshot::install_phantomjs()
# but that function is too simple, always placing the binary in ~/bin/phantomjs
# So I looked at the source code of that function and replaced its functionality with these tasks
- name: Find the URL of the PhantomJS tarball from the latest release of webshot >
curl -s |
jq -r ".assets[] | select(.name | test(\"x86_64\")) | .browser_download_url"
warn: false
register: phantomjs_url
tags: phantomjs
- name: Install PhantomJS
# background: the download task fails when running playbook in check mode, because the task (above)
# the defines phantomjs_url is skipped. So I thought to add a conditional to allow these tasks to
# run without failing in check mode.
# The conditional should allow this task to fail gracefully when running in check mode
# note: in check mode, only the attributes: changed, failed, msg, and skipped are defined
# the OR check for stdout is necessary to avoid conditional failing when *not* in check mode
when: (phantomjs_url.skipped is defined and not phantomjs_url.skipped) or (phantomjs_url.stdout != "")
# unfortunately (for my purposes) this tarball contains a lot of stuff apart from the
# binary (inside bin/) so we have to be quite verbose...
- name: Create a directory to unpack the tarball into
path: "{{ ansible_env.HOME }}/.cache/phantomjs"
state: directory
tags: phantomjs
- name: Download and unpack the PhantomJS tarball
src: "{{ phantomjs_url.stdout }}"
remote_src: yes
dest: "{{ ansible_env.HOME }}/.cache/phantomjs"
extra_opts: "--strip-components=1"
tags: phantomjs
- name: "Install PhantomJS binary to {{ R_bin_path }}"
src: "{{ ansible_env.HOME }}/.cache/phantomjs/bin/phantomjs"
dest: "{{ R_bin_path }}"
remote_src: yes
mode: u=rwx,go=rx
tags: phantomjs