Installing ASDF with Ansible on Debian: A Focus on Ruby
In this article, we will walk you through the process of installing ASDF, a version manager for multiple programming languages, with Ansible on a Debian system. We will focus on the installation of Ruby, as it is one of the most popular programming languages and a great use case for ASDF.
What is ASDF?
ASDF is a command line tool that allows you to manage multiple versions of programming languages, such as Ruby, Node.js, Elixir, and many others. It provides a simple and consistent interface to install and manage different versions of these languages, making it easier to switch between them as needed.
Why use Ansible?
Ansible is an open-source automation tool that enables you to automate the configuration and management of your systems. It is simple to use, yet powerful, and allows you to define your infrastructure as code. With Ansible, you can easily manage multiple systems, making it an ideal tool for managing the installation of ASDF and the programming languages it supports.
Prerequisites
Before we begin, make sure you have the following:
- A Debian system
- Ansible installed
Installing ASDF with Ansible
To install ASDF with Ansible, we will create a playbook called main.yaml and split it into multiple steps. The first step is to install ASDF.
- name: Install ASDF
become: yes
apt:
name: curl
state: present
- name: Install ASDF script
become: yes
copy:
dest: /usr/local/bin/asdf
content: |
#!/bin/bash
if [ -d ~/.asdf ]; then
. ~/.asdf/asdf.sh
else
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.1
echo -e '
. ~/.asdf/asdf.sh' >> ~/.bashrc
fi
mode: '0755'
This playbook installs the required dependencies, downloads the ASDF script, and places it in the /usr/local/bin directory. It also clones the ASDF repository and adds the necessary lines to the ~/.bashrc file to load ASDF at startup.
Installing Ruby with ASDF
Now that we have ASDF installed, we can use it to install Ruby. The following playbook installs Ruby 2.7.2.
- name: Install Ruby
become: yes
command: bash -lc "asdf install ruby 2.7.2"
This playbook uses the command module to execute the asdf install ruby 2.7.2 command, which installs Ruby version 2.7.2.
In this article, we have shown you how to install ASDF, a version manager for programming languages, with Ansible on a Debian system. We have also demonstrated how to use ASDF to install Ruby version 2.7.2. With this setup, you can easily manage multiple versions of Ruby and other programming languages on your system.