Skip to content

Ruby221, idempotent compilation steps #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
version: 1.0.1
galaxy_info:
author: "Joshua Lund"
description: "Ansible role that compiles and installs Ruby (https://www.ruby-lang.org) and Bundler (http://bundler.io)."
Expand Down
67 changes: 31 additions & 36 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,46 @@
---
- name: Update APT cache
apt: update_cache=yes
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

- name: Retrieve the number of cores that are available for compilation
command: nproc
register: cores

- name: Install APT prerequisite packages that are necessary to compile applications and gems with native extensions
apt: pkg={{ item }}
with_items:
- autoconf
- build-essential
- include: setup-debian.yml
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

- name: Install yum prerequisite packages that are necessary to compile applications and gems with native extensions
yum: name="{{ item }}"
with_items:
- autoconf
- "@Developer tools"
- include: setup-redhat.yml
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'Amazon'

- name: Install APT Ruby dependencies
apt: pkg={{ item }}
state=present
with_items: ruby_apt_dependencies
when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu'

- name: Install yum Ruby dependencies
yum: name={{ item }}
with_items: ruby_yum_dependencies
when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'Amazon'
- name: Retrieve the number of cores that are available for compilation
command: nproc
register: cores

- name: Download the Ruby source code
get_url: url={{ ruby_download_location }}
dest=/usr/local/src/
sha256sum={{ ruby_checksum }}

- name: Generate the Ruby installation script
template: src=install-ruby.j2
dest=/usr/local/src/install-ruby.sh
owner=root
group=root
mode=700

- name: Run the Ruby installation script
command: /usr/local/src/install-ruby.sh
creates={{ ruby_location }}/bin/ruby
- name: Extract Ruby source code
command: tar xvfz {{ ruby_source_location }}/{{ ruby_version }}.tar.gz
args:
chdir: "{{ ruby_source_location }}"
creates: "{{ ruby_source_location }}/{{ ruby_version }}"


- name: Configure Ruby
command: ./configure --enable-shared --prefix={{ ruby_location }} --disable-install-doc
args:
chdir: "{{ ruby_source_location }}/{{ ruby_version }}"
creates: "{{ ruby_source_location }}/{{ ruby_version }}/Makefile"


- name: Compile Ruby
command: make --jobs {{ cores.stdout }}
args:
chdir: "{{ ruby_source_location }}/{{ ruby_version }}"
creates: "{{ ruby_source_location }}/{{ ruby_version }}/ruby"

- name: Install Ruby
command: make install
args:
chdir: "{{ ruby_source_location }}/{{ ruby_version }}"
creates: "{{ ruby_location }}/bin/ruby"

- name: Generate the script that allows you to easily run Rake tasks with the correct RAILS_ENV environment variable, and the wrapper script that contains GC settings
template: src={{ item }}.j2
Expand All @@ -66,4 +60,5 @@
file: path=/usr/local/bin/{{ item }}
src={{ ruby_location }}/bin/{{ item }}
state=link
force=true
with_items: ruby_symlinks
14 changes: 14 additions & 0 deletions tasks/setup-debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Update APT cache
apt: update_cache=yes

- name: Install APT prerequisite packages that are necessary to compile applications and gems with native extensions
apt: pkg={{ item }}
with_items:
- autoconf
- build-essential

- name: Install APT Ruby dependencies
apt: pkg={{ item }}
state=present
with_items: ruby_apt_dependencies
10 changes: 10 additions & 0 deletions tasks/setup-redhat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Install yum prerequisite packages that are necessary to compile applications and gems with native extensions
yum: name="{{ item }}"
with_items:
- autoconf
- "@Developer tools"

- name: Install yum Ruby dependencies
yum: name={{ item }}
with_items: ruby_yum_dependencies
8 changes: 0 additions & 8 deletions templates/install-ruby.j2

This file was deleted.

7 changes: 6 additions & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ ruby_apt_dependencies:
- libssl-dev
- libyaml-dev
- zlib1g-dev
- libncurses-dev
- libffi-dev
- libgdbm3


ruby_yum_dependencies:
- readline-devel
Expand All @@ -20,8 +24,9 @@ ruby_symlinks:
- rdoc
- ri
- ruby
- testrb
#- testrb

ruby_location: "/opt/{{ ruby_version }}"
ruby_source_location: /usr/local/src

ruby_executable: "{{ ruby_location }}/bin/ruby"