community.general.gem module – Manage Ruby gems

Note

This module is part of the community.general collection (version 13.1.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.gem.

Synopsis

  • Manage installation and uninstallation of Ruby gems.

Parameters

Parameter

Comments

bindir

path

added in community.general 3.3.0

Install executables into a specific directory.

build_flags

string

Allow adding build flags for gem compilation.

env_shebang

boolean

Rewrite the shebang line on installed scripts to use /usr/bin/env.

Choices:

  • false ← (default)

  • true

executable

path

Override the path to the gem executable.

force

boolean

Force gem to (un-)install, bypassing dependency checks.

Choices:

  • false ← (default)

  • true

gem_source

path

The path to a local gem used as installation source.

include_dependencies

boolean

Whether to include dependencies or not.

Choices:

  • false

  • true ← (default)

include_doc

boolean

Install with or without docs.

Choices:

  • false ← (default)

  • true

install_dir

path

Install the gems into a specific directory. These gems are independent from the global installed ones. Specifying this requires user_install to be false.

name

string / required

The name of the gem to be managed.

norc

boolean

added in community.general 3.3.0

Avoid loading any .gemrc file. Ignored for RubyGems prior to 2.5.2.

The default changed from false to true in community.general 6.0.0.

Choices:

  • false

  • true ← (default)

override_platform_install_dir

boolean

added in community.general 13.0.0

Resolve the user gem installation directory via gem environment and pass it explicitly as --install-dir to both gem install and gem uninstall, instead of using --user-install.

This is needed on distributions (such as Fedora) where a platform-specific operating_system.rb injects --install-dir as a default for all gem commands, which conflicts with --user-install and causes gem uninstall to search the wrong directory.

Cannot be combined with user_install=false or install_dir.

Choices:

  • false ← (default)

  • true

pre_release

boolean

Allow installation of pre-release versions of the gem.

Choices:

  • false ← (default)

  • true

repository

aliases: source

string

The repository from which the gem is installed.

state

string

The desired state of the gem. latest ensures that the latest version is installed.

Choices:

  • "present" ← (default)

  • "absent"

  • "latest"

user_install

boolean

Install gem in user’s local gems cache or for all users.

Choices:

  • false

  • true ← (default)

version

string

Version of the gem to be installed/removed.

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: none

Returns details on what has changed (or possibly needs changing in check_mode), when in diff mode.

Examples

- name: Install version 1.0 of vagrant
  community.general.gem:
    name: vagrant
    version: 1.0
    state: present

- name: Install latest available version of rake
  community.general.gem:
    name: rake
    state: latest

- name: Install rake version 1.0 from a local gem on disk
  community.general.gem:
    name: rake
    gem_source: /path/to/gems/rake-1.0.gem
    state: present

Authors

  • Ansible Core Team

  • Johan Wiren (@johanwiren)