-
-
Save andrewtimberlake/802bd8d285b3e18c5ebe to your computer and use it in GitHub Desktop.
Install ruby from source using Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
roles: | |
- ruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
with_items: | |
- 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 | |
set_fact: | |
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="!=")))' | |
- name: Download Ruby | |
when: ruby_installed_version|failed or ruby_reinstall_from_source | |
get_url: | |
url: "https://cache.ruby-lang.org/pub/ruby/2.3/ruby-{{ruby_version}}.tar.gz" | |
dest: "/tmp/ruby-{{ruby_version}}.tar.gz" | |
sha256sum: "{{ruby_sha256sum}}" | |
- name: Extract archive | |
when: ruby_installed_version|failed or ruby_reinstall_from_source | |
unarchive: | |
src: "/tmp/ruby-{{ruby_version}}.tar.gz" | |
dest: /tmp/ | |
creates: "/tmp/ruby-{{ruby_version}}/README.md" | |
copy: false | |
- name: Configure install | |
when: ruby_installed_version|failed or ruby_reinstall_from_source | |
command: ./configure --disable-install-doc | |
args: | |
chdir: "/tmp/ruby-{{ruby_version}}" | |
creates: "/tmp/ruby-{{ruby_version}}/config.status" | |
- name: Build ruby | |
when: ruby_installed_version|failed or ruby_reinstall_from_source | |
command: make | |
args: | |
chdir: "/tmp/ruby-{{ruby_version}}" | |
creates: "/tmp/ruby-{{ruby_version}}/ruby" | |
- name: Install ruby | |
when: ruby_installed_version|failed or ruby_reinstall_from_source | |
become: true | |
command: make install | |
args: | |
chdir: "/tmp/ruby-{{ruby_version}}" | |
creates: /usr/local/bin/ruby | |
- name: Remove build directory | |
when: ruby_installed_version|failed or ruby_reinstall_from_source | |
file: | |
path: "/tmp/ruby-{{ruby_version}}" | |
state: absent | |
- name: Remove archive | |
when: ruby_installed_version|failed or ruby_reinstall_from_source | |
file: | |
path: "/tmp/ruby-{{ruby_version}}.tar.gz" | |
state: absent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[test] | |
ec2-127-0-0-1.eu-west-1.compute.amazonaws.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment