suzuki-shunsuke.rbenv-module
ansible-rbenv-module
This is an Ansible module for running rbenv commands.
You can find it here: ansible-rbenv-module
Important Note
- This module does not support check mode
Supported Platforms
- Generic Linux
- macOS
We have tested this module on:
- Ubuntu 16.04 (using Vagrant with VirtualBox)
- CentOS 7.3 (using Vagrant with VirtualBox)
- macOS Sierra 10.12.5
Requirements
To use this module, please ensure you have:
If you want to install rbenv, ruby-build, and their dependencies using Ansible, we recommend using the suzuki-shunsuke.rbenv role.
Supported rbenv Commands
You can use the following commands with this module:
$ rbenv install [--skip-existing] [--force] <version>
$ rbenv uninstall --force <version>
$ rbenv install --list
$ rbenv versions [--bare] [--skip-aliases]
$ rbenv global
$ rbenv global <version>
Installation
You can install the module using the command:
$ ansible-galaxy install suzuki-shunsuke.rbenv-module
Then, include the module in your playbook like this:
# playbook.yml
- hosts: default
roles:
# This role allows you to use the module.
- suzuki-shunsuke.rbenv-module
Options
Please also refer to the rbenv command reference and use rbenv help <command>
for additional information.
Common Options
Name | Type | Required | Default | Choices/Example | Description |
---|---|---|---|---|---|
subcommand | str | no | install | [install, uninstall, versions, global] | The rbenv command you want to use. |
rbenv_root | str | no | ~/.rbenv | Required if the "RBENV_ROOT" environment variable is not set. | |
expanduser | bool | no | yes | If true, filters the "RBENV_ROOT" variable and "rbenv_root" option for the home directory. |
Options for the "install" Command
Parameter | Type | Required | Default | Choices/Example | Description |
---|---|---|---|---|---|
version | str | no | 2.4.0 | The version of Ruby to install. | |
list | bool | no | no | Set to true for the -l option to list available versions. | |
skip_existing | bool | no | yes | Set to true for the -s option to skip already existing versions. | |
force | bool | no | no | Set to true for the -f option to force the installation. |
You must provide either "version" or "list". If you use "list", the task will return available versions.
Options for the "uninstall" Command
Parameter | Type | Required | Default | Choices/Example | Description |
---|---|---|---|---|---|
version | str | yes | 2.4.0 | The version of Ruby to uninstall. |
Options for the "global" Command
Parameter | Type | Required | Default | Choices | Description |
---|---|---|---|---|---|
version | str | no | Set the global Ruby version. |
The "global" command will return the current global version.
Options for the "versions" Command
Parameter | Type | Required | Default | Choices | Description |
---|---|---|---|---|---|
bare | bool | no | yes | If true, will return only version numbers. | |
skip_aliases | bool | no | yes | Set to true to skip alias versions with the --skip-aliases option. |
The "versions" command will return all available versions.
Example Playbook
Here’s an example of how to use this module in a playbook:
- name: List available Ruby versions
rbenv:
list: yes
rbenv_root: "~/.rbenv"
register: result
failed_when: result.failed or result.changed
- debug:
var: result.versions
- name: Set global Ruby version
rbenv:
subcommand: global
version: 2.4.0
rbenv_root: "~/.rbenv"
register: result
failed_when: result.failed or result.changed
- debug:
var: result
- name: Install Ruby version 2.4.0
rbenv:
version: 2.4.0
rbenv_root: "~/.rbenv"
- name: List installed Ruby versions
rbenv:
subcommand: versions
rbenv_root: "~/.rbenv"
register: result
failed_when: result.failed or result.changed
- debug:
var: result.versions
- name: Uninstall Ruby version 2.3.1
rbenv:
subcommand: uninstall
version: 2.3.1
environment:
RBENV_ROOT: "~/.rbenv"
register: result
Tips
Installing Ruby Packages with gem
This module does not directly support the gem
command, but you can use the official gem module like this:
# Install Ruby and create a virtual environment before using the gem module
- name: Install Ruby version 2.4.0
rbenv:
rbenv_root: "{{rbenv_root}}"
version: 2.4.0
# Use the gem module with the executable option
- name: Install Rake gem on Ruby version 2.4.0
gem:
name: rake
executable: "{{rbenv_root}}/versions/2.4.0/bin/gem"
Change Log
For updates, see CHANGELOG.md.
Related Links
- suzuki-shunsuke.rbenv: Ansible role for installing rbenv
License
Development Setup
Requirements
- Vagrant
- Ansible
- Node.js
- Yarn
Setup Instructions
$ yarn install
$ cd tests
$ ansible-galaxy install -r roles.yml
Testing
$ cd tests
$ vagrant up --provision
ansible-galaxy install suzuki-shunsuke.rbenv-module