diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml index 1fd1463..e647ab5 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -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)." diff --git a/tasks/main.yml b/tasks/main.yml index 59a55da..1c5bf2b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 @@ -66,4 +60,5 @@ file: path=/usr/local/bin/{{ item }} src={{ ruby_location }}/bin/{{ item }} state=link + force=true with_items: ruby_symlinks diff --git a/tasks/setup-debian.yml b/tasks/setup-debian.yml new file mode 100644 index 0000000..cf554bc --- /dev/null +++ b/tasks/setup-debian.yml @@ -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 diff --git a/tasks/setup-redhat.yml b/tasks/setup-redhat.yml new file mode 100644 index 0000000..f4dfad2 --- /dev/null +++ b/tasks/setup-redhat.yml @@ -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 diff --git a/templates/install-ruby.j2 b/templates/install-ruby.j2 deleted file mode 100644 index a58e427..0000000 --- a/templates/install-ruby.j2 +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -cd /usr/local/src/ -tar xvfz {{ ruby_version }}.tar.gz -cd {{ ruby_version }} -./configure --prefix={{ ruby_location }} --disable-install-doc -make --jobs {{ cores.stdout }} -make install diff --git a/vars/main.yml b/vars/main.yml index 078ac76..049e976 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -4,6 +4,10 @@ ruby_apt_dependencies: - libssl-dev - libyaml-dev - zlib1g-dev + - libncurses-dev + - libffi-dev + - libgdbm3 + ruby_yum_dependencies: - readline-devel @@ -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"