├── .ansible-lint ├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ ├── release.yml │ └── stale.yml ├── .gitignore ├── .yamllint ├── LICENSE ├── README.md ├── defaults └── main.yml ├── files └── rubygems.sh ├── meta └── main.yml ├── molecule └── default │ ├── converge.yml │ ├── molecule.yml │ └── source-install.yml ├── tasks ├── install-from-source.yml ├── main.yml ├── setup-Debian.yml └── setup-RedHat.yml └── vars ├── Debian.yml └── RedHat.yml /.ansible-lint: -------------------------------------------------------------------------------- 1 | skip_list: 2 | - 'yaml' 3 | - 'role-name' 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | --- 3 | github: geerlingguy 4 | patreon: geerlingguy 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: CI 3 | 'on': 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | schedule: 9 | - cron: "0 3 * * 4" 10 | 11 | defaults: 12 | run: 13 | working-directory: 'geerlingguy.ruby' 14 | 15 | jobs: 16 | 17 | lint: 18 | name: Lint 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Check out the codebase. 22 | uses: actions/checkout@v4 23 | with: 24 | path: 'geerlingguy.ruby' 25 | 26 | - name: Set up Python 3. 27 | uses: actions/setup-python@v5 28 | with: 29 | python-version: '3.x' 30 | 31 | - name: Install test dependencies. 32 | run: pip3 install yamllint 33 | 34 | - name: Lint code. 35 | run: | 36 | yamllint . 37 | 38 | molecule: 39 | name: Molecule 40 | runs-on: ubuntu-latest 41 | strategy: 42 | matrix: 43 | include: 44 | # See: https://github.com/geerlingguy/docker-rockylinux9-ansible/issues/6 45 | # - distro: rockylinux9 46 | # playbook: converge.yml 47 | - distro: ubuntu2204 48 | playbook: converge.yml 49 | - distro: debian11 50 | playbook: converge.yml 51 | 52 | - distro: ubuntu2004 53 | playbook: source-install.yml 54 | 55 | steps: 56 | - name: Check out the codebase. 57 | uses: actions/checkout@v4 58 | with: 59 | path: 'geerlingguy.ruby' 60 | 61 | - name: Set up Python 3. 62 | uses: actions/setup-python@v5 63 | with: 64 | python-version: '3.x' 65 | 66 | - name: Install test dependencies. 67 | run: pip3 install ansible molecule molecule-plugins[docker] docker 68 | 69 | - name: Run Molecule tests. 70 | run: molecule test 71 | env: 72 | PY_COLORS: '1' 73 | ANSIBLE_FORCE_COLOR: '1' 74 | MOLECULE_DISTRO: ${{ matrix.distro }} 75 | MOLECULE_PLAYBOOK: ${{ matrix.playbook }} 76 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This workflow requires a GALAXY_API_KEY secret present in the GitHub 3 | # repository or organization. 4 | # 5 | # See: https://github.com/marketplace/actions/publish-ansible-role-to-galaxy 6 | # See: https://github.com/ansible/galaxy/issues/46 7 | 8 | name: Release 9 | 'on': 10 | push: 11 | tags: 12 | - '*' 13 | 14 | defaults: 15 | run: 16 | working-directory: 'geerlingguy.ruby' 17 | 18 | jobs: 19 | 20 | release: 21 | name: Release 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Check out the codebase. 25 | uses: actions/checkout@v4 26 | with: 27 | path: 'geerlingguy.ruby' 28 | 29 | - name: Set up Python 3. 30 | uses: actions/setup-python@v5 31 | with: 32 | python-version: '3.x' 33 | 34 | - name: Install Ansible. 35 | run: pip3 install ansible-core 36 | 37 | - name: Trigger a new import on Galaxy. 38 | run: >- 39 | ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }} 40 | $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2) 41 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Close inactive issues 3 | 'on': 4 | schedule: 5 | - cron: "55 11 * * 5" # semi-random time 6 | 7 | jobs: 8 | close-issues: 9 | runs-on: ubuntu-latest 10 | permissions: 11 | issues: write 12 | pull-requests: write 13 | steps: 14 | - uses: actions/stale@v8 15 | with: 16 | days-before-stale: 120 17 | days-before-close: 60 18 | exempt-issue-labels: bug,pinned,security,planned 19 | exempt-pr-labels: bug,pinned,security,planned 20 | stale-issue-label: "stale" 21 | stale-pr-label: "stale" 22 | stale-issue-message: | 23 | This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 24 | 25 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 26 | close-issue-message: | 27 | This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 28 | stale-pr-message: | 29 | This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 30 | 31 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 32 | close-pr-message: | 33 | This pr has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 34 | repo-token: ${{ secrets.GITHUB_TOKEN }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.retry 2 | */__pycache__ 3 | *.pyc 4 | .cache 5 | 6 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | 4 | rules: 5 | line-length: 6 | max: 120 7 | level: warning 8 | 9 | ignore: | 10 | .github/workflows/stale.yml 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Jeff Geerling 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role: Ruby 2 | 3 | [![CI](https://github.com/geerlingguy/ansible-role-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/geerlingguy/ansible-role-ruby/actions/workflows/ci.yml) 4 | 5 | Installs Ruby and bundler gem on Linux. 6 | 7 | ## Requirements 8 | 9 | None. 10 | 11 | ## Role Variables 12 | 13 | Available variables are listed below, along with default values (see `defaults/main.yml`): 14 | 15 | workspace: /root 16 | 17 | The location where temporary files will be downloaded in preparation for Ruby installation. 18 | 19 | ruby_install_bundler: true 20 | 21 | Whether this role should install [Bundler](http://bundler.io/). 22 | 23 | ruby_install_gems: [] 24 | 25 | A list of Ruby gems to install (just the name of the gem to be installed). This is meant as a simple convenience, and will only install the latest version of the gem. If you need to install gems with more options or specificity, you can do so elsewhere in your playbook. 26 | 27 | You can also use a dictionary for each gem that allows setting the `version` and 28 | `user_install` keys for the `gem` Ansible module. For example: 29 | 30 | ruby_install_gems: 31 | - name: bundler 32 | version: '< 2' 33 | user_install: false 34 | 35 | You can mix the two syntaxes, using either a dict or a string (the gem name) for each gem. 36 | 37 | ruby_install_gems_user: username 38 | 39 | The user account under which Ruby gems will be installed. Defaults to the `ansible_ssh_user` if not set. 40 | 41 | ruby_install_from_source: false 42 | 43 | By default, this role will install whatever version of ruby is available through your system's package manager (`apt` or `yum`). You can install whatever version you like (including the latest release) by setting this to `true` and/or updating the `ruby_download_url` and `ruby_version`. 44 | 45 | ruby_download_url: http://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz 46 | 47 | The URL from which Ruby will be downloaded (only used if `ruby_install_from_source` is `true`). 48 | 49 | ruby_version: 3.0.0 50 | 51 | The version of ruby that will be installed (only used if `ruby_install_from_source` is `true`). 52 | 53 | ruby_source_configure_command: ./configure --enable-shared 54 | 55 | The `configure` command that will be run (only used if `ruby_install_from_source` is `true`). 56 | 57 | ruby_rubygems_package_name: rubygems 58 | 59 | The name of the `rubygems` package. Generally, the default should work; but it will be set to `rubygems-integration` automatically on Ubuntu Trusty (14.04). 60 | 61 | ## Dependencies 62 | 63 | None. 64 | 65 | ## Example Playbook 66 | 67 | - hosts: server 68 | roles: 69 | - role: geerlingguy.ruby 70 | 71 | ## License 72 | 73 | MIT / BSD 74 | 75 | ## Author Information 76 | 77 | This role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). 78 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | workspace: /root 3 | 4 | # Whether this role should install Bundler. 5 | ruby_install_bundler: true 6 | 7 | # A list of Ruby gems to install. 8 | ruby_install_gems: [] 9 | 10 | # The user account under which Ruby gems will be installed. 11 | ruby_install_gems_user: "{{ ansible_user }}" 12 | 13 | # If set to True, ruby will be installed from source, using the version set with 14 | # the 'ruby_version' variable instead of using a package. 15 | ruby_install_from_source: false 16 | ruby_download_url: http://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz 17 | ruby_version: 3.0.0 18 | ruby_source_configure_command: ./configure --enable-shared 19 | 20 | # Default should usually work, but this will be overridden on Ubuntu 14.04. 21 | ruby_rubygems_package_name: rubygems 22 | -------------------------------------------------------------------------------- /files/rubygems.sh: -------------------------------------------------------------------------------- 1 | if which ruby >/dev/null && which gem >/dev/null; then 2 | PATH="$(ruby -e 'puts Gem.user_dir')/bin:$PATH" 3 | fi 4 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: [] 3 | 4 | galaxy_info: 5 | role_name: ruby 6 | author: geerlingguy 7 | description: Ruby installation for Linux. 8 | company: "Midwestern Mac, LLC" 9 | license: "license (BSD, MIT)" 10 | min_ansible_version: 2.10 11 | platforms: 12 | - name: GenericUNIX 13 | versions: 14 | - all 15 | - name: Fedora 16 | versions: 17 | - all 18 | - name: opensuse 19 | versions: 20 | - all 21 | - name: GenericBSD 22 | versions: 23 | - all 24 | - name: FreeBSD 25 | versions: 26 | - all 27 | - name: Ubuntu 28 | versions: 29 | - lucid 30 | - trusty 31 | - precise 32 | - bionic 33 | - name: SLES 34 | versions: 35 | - all 36 | - name: GenericLinux 37 | versions: 38 | - all 39 | - name: Debian 40 | versions: 41 | - all 42 | galaxy_tags: 43 | - development 44 | - web 45 | - ruby 46 | - rails 47 | - gem 48 | - bundler 49 | -------------------------------------------------------------------------------- /molecule/default/converge.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | #become: true 5 | 6 | vars: 7 | ruby_install_gems_user: root 8 | ruby_install_gems: 9 | - json 10 | ruby_gems_bin_path: /root/.gem/ruby/bin 11 | 12 | pre_tasks: 13 | - name: Update apt cache. 14 | apt: update_cache=true cache_valid_time=600 15 | when: ansible_os_family == 'Debian' 16 | 17 | - name: Add rubygems bin dir to system-wide $PATH. 18 | copy: 19 | dest: /etc/profile.d/ruby.sh 20 | content: 'PATH=$PATH:{{ ruby_gems_bin_path }}' 21 | mode: 0644 22 | 23 | - name: Don't install Bundler on CentOS 7 because of old Ruby version. 24 | set_fact: 25 | ruby_install_bundler: false 26 | when: 27 | - ansible_os_family == 'RedHat' 28 | - ansible_distribution_major_version == '7' 29 | 30 | roles: 31 | - role: geerlingguy.ruby 32 | 33 | post_tasks: 34 | - name: Verify Ruby is installed. 35 | command: ruby --version 36 | changed_when: false 37 | -------------------------------------------------------------------------------- /molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | role_name_check: 1 3 | dependency: 4 | name: galaxy 5 | options: 6 | ignore-errors: true 7 | driver: 8 | name: docker 9 | platforms: 10 | - name: instance 11 | image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux9}-ansible:latest" 12 | command: ${MOLECULE_DOCKER_COMMAND:-""} 13 | volumes: 14 | - /sys/fs/cgroup:/sys/fs/cgroup:rw 15 | cgroupns_mode: host 16 | privileged: true 17 | pre_build_image: true 18 | provisioner: 19 | name: ansible 20 | playbooks: 21 | converge: ${MOLECULE_PLAYBOOK:-converge.yml} 22 | -------------------------------------------------------------------------------- /molecule/default/source-install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | #become: true 5 | 6 | vars: 7 | ruby_install_from_source: true 8 | ruby_install_gems_user: root 9 | ruby_install_gems: 10 | - sass 11 | 12 | pre_tasks: 13 | - name: Update apt cache. 14 | apt: update_cache=true cache_valid_time=600 15 | when: ansible_os_family == 'Debian' 16 | 17 | roles: 18 | - role: geerlingguy.ruby 19 | 20 | post_tasks: 21 | - name: Verify Ruby is installed. 22 | command: ruby --version 23 | changed_when: false 24 | -------------------------------------------------------------------------------- /tasks/install-from-source.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Define ruby_build_packages. 3 | set_fact: 4 | ruby_build_packages: "{{ __ruby_build_packages }}" 5 | when: ruby_build_packages is not defined 6 | 7 | - name: Install packages required to build ruby. 8 | yum: 9 | name: "{{ ruby_build_packages }}" 10 | state: present 11 | when: ansible_os_family == 'RedHat' 12 | 13 | - name: Update apt cache (Debian). 14 | apt: update_cache=true cache_valid_time=86400 15 | when: ansible_os_family == 'Debian' 16 | 17 | - name: Install packages required to build ruby (Debian). 18 | apt: 19 | name: "{{ ruby_build_packages }}" 20 | state: present 21 | when: ansible_os_family == 'Debian' 22 | 23 | - name: Ensure that /var/cache/ansible/ exists 24 | file: 25 | path: "/var/cache/ansible/" 26 | state: directory 27 | 28 | - name: Check if ruby is up-to-date 29 | stat: 30 | path: "/var/cache/ansible/ruby-{{ ruby_version }}.check" 31 | register: ruby_version_marker 32 | 33 | - name: Download, extract, and install ruby 34 | when: not ruby_version_marker.stat.exists 35 | block: 36 | - name: Download ruby. 37 | get_url: 38 | url: "{{ ruby_download_url }}" 39 | dest: "{{ workspace }}/ruby-{{ ruby_version }}.tar.gz" 40 | 41 | - name: Extract ruby. 42 | unarchive: 43 | src: "{{ workspace }}/ruby-{{ ruby_version }}.tar.gz" 44 | dest: "{{ workspace }}/" 45 | copy: false 46 | mode: 0755 47 | 48 | - name: Build ruby. 49 | command: > 50 | {{ item }} 51 | chdir={{ workspace }}/ruby-{{ ruby_version }} 52 | with_items: 53 | - "{{ ruby_source_configure_command }}" 54 | - make 55 | - make install 56 | 57 | - name: Touch install-marker 58 | file: 59 | path: "/var/cache/ansible/ruby-{{ ruby_version }}.check" 60 | state: touch 61 | 62 | - name: Add ruby symlinks. 63 | file: # noqa 208 64 | src: "/usr/local/bin/{{ item }}" 65 | dest: "/usr/bin/{{ item }}" 66 | state: link 67 | force: true 68 | with_items: 69 | - erb 70 | - gem 71 | - irb 72 | - rake 73 | - rdoc 74 | - ruby 75 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Include OS-specific variables. 3 | include_vars: "{{ ansible_os_family }}.yml" 4 | 5 | - name: Define ruby_packages. 6 | set_fact: 7 | ruby_packages: "{{ __ruby_packages }}" 8 | when: ruby_packages is not defined 9 | 10 | # Include OS-specific installation tasks. 11 | - include_tasks: setup-RedHat.yml 12 | when: 13 | - not ruby_install_from_source 14 | - ansible_os_family == 'RedHat' 15 | 16 | - include_tasks: setup-Debian.yml 17 | when: 18 | - not ruby_install_from_source 19 | - ansible_os_family == 'Debian' 20 | 21 | # Install ruby from source when ruby_install_from_source is true. 22 | - include_tasks: install-from-source.yml 23 | when: ruby_install_from_source 24 | 25 | - name: Add user installed RubyGems bin directory to global $PATH. 26 | copy: 27 | src: rubygems.sh 28 | dest: /etc/profile.d/rubygems.sh 29 | mode: 0644 30 | 31 | # Install Bundler and configured gems. 32 | - name: Install Bundler. 33 | gem: 34 | name: bundler 35 | state: present 36 | user_install: false 37 | when: ruby_install_bundler 38 | 39 | - name: Install configured gems. 40 | gem: 41 | name: "{{ item.name | default(item) }}" 42 | version: "{{ item.version | default(omit) }}" 43 | user_install: "{{ item.user_install | default(omit) }}" 44 | state: present 45 | become: true 46 | become_user: "{{ ruby_install_gems_user }}" 47 | with_items: "{{ ruby_install_gems }}" 48 | -------------------------------------------------------------------------------- /tasks/setup-Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Update apt cache. 3 | apt: 4 | update_cache: true 5 | cache_valid_time: 86400 6 | 7 | - name: Set rubygems package name for Ubuntu 14.04. 8 | set_fact: 9 | ruby_rubygems_package_name: rubygems-integration 10 | when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'trusty' 11 | 12 | - name: Install ruby and other required dependencies. 13 | apt: 14 | name: "{{ ruby_packages }}" 15 | state: present 16 | 17 | - name: Install rubygems. 18 | apt: 19 | name: "{{ ruby_rubygems_package_name }}" 20 | state: present 21 | -------------------------------------------------------------------------------- /tasks/setup-RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install ruby, rubygems, and development tools. 3 | yum: 4 | name: "{{ ruby_packages }}" 5 | state: present 6 | -------------------------------------------------------------------------------- /vars/Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | __ruby_packages: 3 | - ruby-full 4 | - ruby-dev 5 | - build-essential 6 | - autogen 7 | - autoconf 8 | - libtool 9 | __ruby_build_packages: 10 | - build-essential 11 | - zlib1g-dev 12 | - libssl-dev 13 | - libyaml-dev 14 | - libreadline6-dev 15 | - libncurses5-dev 16 | - libffi-dev 17 | - libgdbm-dev 18 | -------------------------------------------------------------------------------- /vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | __ruby_packages: 3 | - ruby 4 | - ruby-devel 5 | - "{{ ruby_rubygems_package_name }}" 6 | - '@development tools' 7 | __ruby_build_packages: 8 | - '@development tools' 9 | - zlib-devel 10 | - openssl-static 11 | --------------------------------------------------------------------------------