Using Ansible to Install R and Workbench

Follow

Using Ansible to Install R and Workbench on RedHat/ Centos/ Rocky Linux Servers

IMPORTANT: Ansible installation and support is outside the scope of Posit Support. The following instructions are for guidance only, and they should be modified based on your OS/Linux environment and your specific needs. For more information on Ansible, see the resource here; https://docs.ansible.com/ansible/latest/.

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, installations, and application deployment. 

Benefits of using Ansible:

  • Free: Ansible is an open-source tool.
  • Simple setup: No special coding skills are necessary to use Ansible’s playbooks.
  • Powerful: Ansible lets you model even highly complex IT workflows. 
  • Agentless: You don’t need to install any other software or firewall ports on the client systems you want to automate. 
  • Efficient: Because you don’t need to install any extra software, there’s more room for application resources on your server.

Use-Case:

  • Install, and upgrade Posit products
  • Start and stop services.
  • Perform a wide variety of configuration tasks.
  • Implement a security policy.

Using Ansible to install WorkBench

Prerequisites:

  • RPM-based Linux Server from Ansible will be run ("the Ansible server")
  • Inventory file of the target servers on the Ansible server. 
  • Download and install EPEL repository
  • Install Ansible packages from the EPEL repository
  • Create a playbook to deploy the product, typically titled workbench.yml

Follow the steps below to install Ansible on RHEL/CentOS 8

Step 1:

Update /etc/hosts file with the hostname and IP details of your Ansible server and managed hosts in your setup.

# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

10.10.10.21   ansible    ansible.example.com
10.10.10.25   host1        host1.example.com
10.10.10.26   host2        host2.example.com

Step 2

Download and install the EPEL repository using your package manager of choice (RPM/YUM/DNF);

 # rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

# dnf -y install epel-release

Step 3:

Install Ansible:

# dnf -y install ansible

 

Step 4:

Validate that ansible is installed. 

# ansible -–version

************** Done! Ansible is installed. *******************

Next, create an inventory file with the hosts you would like to deploy the product on.

Example:

# touch myhosts.txt && vi myhosts.txt
[hosts]
host1
host2
host3

After that, create a playbook; you can use the template below as an example:

Note: The example below is based on the Rocky Linux distribution of Linux; please customize your code to fit your Linux distribution and environment.

- name: update server
  yum:
    name: '*'
    state: latest

- name: Install EPEL Repo
  yum:
    name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
    state: latest

- name: Install dnf-plugins-core
  yum:
    name: dnf-plugins-core
    state: present

# use this parameter for Rocky linux and comment out the next codeReady parameter.
#- name: Enable powertools
#  community.general.ini_file:
#    path: "/etc/yum.repos.d/Rocky-PowerTools.repo"
#    section: powertools
#    option: enabled
#    value: "1"
#    mode: "0644"

#  notify:
#    - Yum update cache

- name: Enable the CodeReady Linux Builder repository
  command: sudo subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms

- name: Export R Version

  shell: export R_VERSION=4.2.2

- name: Download R
  shell: curl -O https://cdn.rstudio.com/r/centos-8/pkgs/R-4.2.2-1-1.x86_64.rpm

- name: Install R
  shell: sudo yum install R-4.2.2-1-1.x86_64.rpm -y

- name: Create a symlink to R
  shell: sudo ln -snf /opt/R/4.2.2/bin/R /usr/local/bin/R

- name: Create a symlink to RScripts
  shell: sudo ln -snf /opt/R/4.2.2/bin/Rscript /usr/local/bin/Rscript

- name: Download WorkBench_2022-12 for RHEL8
  shell: curl -O https://download2.rstudio.org/server/rhel8/x86_64/rstudio-workbench-rhel-2022.12.0-353.pro20-x86_64.rpm

- name: Install WorkBench
  shell: sudo yum install rstudio-workbench-rhel-2022.12.0-353.pro20-x86_64.rpm -y

- name: Restart rstudio-service
  ansible.builtin.service:
    name: rstudio-server
    state: restarted


For more information about ansible, see here

Comments