# Problem
I would like to use ansible to provision a virtual box. This box will need to do multiple things, but it needs to have R installed as well as some specific packages that aren't included in base R.
I use the vagrant file provided below to create a new virtual machine and then install ansible, epel-release and git using yum. On this virtual machine I then use the "Alma Linux 8" and "Docker" playbooks provided below before the one I believe to be problematic.
I then run this playbook to install R
---
- name: "Setup R on the local machine"
hosts: localhost
connection: local
tasks:
# Update all installed packages
- name: Update all packages to their latest version
become: yes
ansible.builtin.package:
name: "*"
state: latest
# Install EPEL to get extra packages
- name: Install EPEL
become: yes
ansible.builtin.package:
name: epel-release
state: latest
# Enable the Code Ready Builder (CRB) repository
- name: Install utilities to enable package repositories
become: yes
ansible.builtin.package:
name: yum-utils
state: latest
- name: Enable the PowerTools repository
become: yes
shell: dnf config-manager --set-enabled powertools
# Install R
- name: Install R
become: yes
ansible.builtin.package:
name: R
state: latest
After running this playbook I can then run the command
Rscript --slave --no-save --no-restore-history -e "print('Test')"
"Test"
showing that R is working at least in some capacity. But then when I try and use this to install a package I get this error
Rscript --slave --no-save --no-restore-history -e "install.packages('tidyverse')"
> Installing package into ‘/usr/lib64/R/library’
> (as ‘lib’ is unspecified)
> Warning in install.packages("tidyverse") :
> 'lib = "/usr/lib64/R/library"' is not writable
> Error in install.packages("tidyverse") : unable to install packages
> Execution halted
# Attempted Fix #
I have attempted to fix this by appending these lines on to the end of the R playbook above
- name: Make directory writable
become: yes
file:
path: /usr/lib64/R/library
mode: '0777'
- name: Make directory writable
become: yes
file:
path: /usr/share/doc/R/html
mode: '0777'
to manually make the problematic directories readable, but this has not worked.
# Reference Files #
## Vagrant File ##
Vagrant.configure("2") do |config|
config.vm.box = "almalinux/8"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
vb.cpus = 2
end
end
## Ansible Playbooks ##
### Alma Linux 8 ###
---
- name: "Setup AlmaLinux 8 on the local machine"
hosts: localhost
connection: local
tasks:
# Install the base operating systemctl
- name: Update all packages to their latest versions
become: yes
ansible.builtin.package:
name: '*'
state: latest
- name: Install virtual machine support
become: yes
ansible.builtin.package:
name: open-vm-tools
state: latest
# Install EPEL to get extra packages
- name: Install EPEL
become: yes
ansible.builtin.package:
name: epel-release
state: latest
### Docker ###
---
- name: "Setup Docker on the local machine"
hosts: localhost
connection: local
tasks:
# Install Docker
- name: Uninstall any older versions of Docker
become: yes
ansible.builtin.package:
name:
- docker
- docker-client
- docker-client-latest
- docker-common
- docker-latest
- docker-latest-logrotate
- docker-logrotate
- docker-engine
state: absent
- name: Install yum-utils to install a new package repository
become: yes
ansible.builtin.package:
name: yum-utils
state: latest
- name: Install the Docker Repository
become: yes
shell: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- name: Install Docker
become: yes
ansible.builtin.package:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: latest
- name: Enable the docker service
become: yes
shell: systemctl enable docker
- name: Enable the containerd service
become: yes
shell: systemctl enable containerd
- name: Start the docker service
become: yes
shell: systemctl start docker
- name: Start the containerd service
become: yes
shell: systemctl start containerd
- name: Ensure docker group exists
become: yes
ansible.builtin.group:
name: docker
state: present
- name: Add the vagrant user to the docker group
become: yes
ansible.builtin.user:
name: vagrant
groups: docker
append: yes
Asked by Hugh Warden
(103 rep)
Oct 23, 2023, 01:45 AM
Last activity: Oct 23, 2023, 03:38 AM
Last activity: Oct 23, 2023, 03:38 AM