Create a gist now

Instantly share code, notes, and snippets.

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_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: 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