Skip to content

Instantly share code, notes, and snippets.

Last active May 4, 2021 20:50
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Install ruby from source using Ansible
# group_vars/test.yml
# This file contains the variables needed for the [test] host group
ruby_reinstall_from_source: false
ruby_version: 2.3.0
ruby_sha256sum: ba5ba60e5f1aa21b4ef8e9bf35b9ddb57286cb546aac4b5a28c71f459467e507
# playbook.yml
# This file is the main build configuration
- name: "Test Playbook" # The name of the playbook
hosts: test # The servers in this host group will be affected
remote_user: ubuntu # The user we are going to log in as
become_method: sudo # The method we will become another user via
- ruby
# roles/ruby/tasks/main.yml
# This file contains all the tasks that will be run for the ruby play
- name: install required packages
become: true
apt: name={{item}} state=present update_cache=yes
- build-essential
- cmake
- zlib1g-dev
- libyaml-dev
- libncurses-dev
- libssl-dev
- libreadline-dev
- name: Get installed version
command: ruby --version
ignore_errors: True
changed_when: false
failed_when: false
register: ruby_installed_version
- name: Force install if the version numbers do not match
ruby_reinstall_from_source: true
when: '(ruby_installed_version|success and (ruby_installed_version.stdout | regex_replace("^.*?([0-9\.]+).*$", "\\1") | version_compare(ruby_version, operator="!=")))'
- when: ruby_installed_version|failed or ruby_reinstall_from_source
- name: Download Ruby
url: "{{ruby_version}}.tar.gz"
dest: "/tmp/ruby-{{ruby_version}}.tar.gz"
sha256sum: "{{ruby_sha256sum}}"
- name: Extract archive
src: "/tmp/ruby-{{ruby_version}}.tar.gz"
dest: /tmp/
creates: "/tmp/ruby-{{ruby_version}}/"
copy: false
- name: Configure install
command: ./configure --disable-install-doc
chdir: "/tmp/ruby-{{ruby_version}}"
creates: "/tmp/ruby-{{ruby_version}}/config.status"
- name: Build ruby
command: make
chdir: "/tmp/ruby-{{ruby_version}}"
creates: "/tmp/ruby-{{ruby_version}}/ruby"
- name: Install ruby
become: true
command: make install
chdir: "/tmp/ruby-{{ruby_version}}"
creates: /usr/local/bin/ruby
- name: Remove build directory
path: "/tmp/ruby-{{ruby_version}}"
state: absent
- name: Remove archive
path: "/tmp/ruby-{{ruby_version}}.tar.gz"
state: absent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment