1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add executable parameter to find gem binary in gem module

This is especially needed with rvm where gem binary can be in unusual locations
This commit is contained in:
Mickaël Rémond 2013-10-15 09:08:33 +02:00
parent 0cd09dd54f
commit 007a3fe154

View file

@ -57,6 +57,11 @@ options:
required: false required: false
default: "yes" default: "yes"
version_added: "1.3" version_added: "1.3"
executable:
description:
- Override the path to the gem executable
required: false
version_added: "1.4"
version: version:
description: description:
- Version of the gem to be installed/removed. - Version of the gem to be installed/removed.
@ -77,8 +82,14 @@ EXAMPLES = '''
import re import re
def get_rubygems_path(module):
if module.params['executable']:
return module.params['executable']
else:
return module.get_bin_path('gem', True)
def get_rubygems_version(module): def get_rubygems_version(module):
cmd = [module.get_bin_path('gem', True), '--version'] cmd = [get_rubygems_path(module), '--version']
(rc, out, err) = module.run_command(cmd, check_rc=True) (rc, out, err) = module.run_command(cmd, check_rc=True)
match = re.match(r'^(\d+)\.(\d+)\.(\d+)', out) match = re.match(r'^(\d+)\.(\d+)\.(\d+)', out)
@ -89,7 +100,7 @@ def get_rubygems_version(module):
def get_installed_versions(module, remote=False): def get_installed_versions(module, remote=False):
cmd = [ module.get_bin_path('gem', True) ] cmd = [ get_rubygems_path(module) ]
cmd.append('query') cmd.append('query')
if remote: if remote:
cmd.append('--remote') cmd.append('--remote')
@ -126,7 +137,7 @@ def uninstall(module):
if module.check_mode: if module.check_mode:
return return
cmd = [ module.get_bin_path('gem', True) ] cmd = [ get_rubygems_path(module) ]
cmd.append('uninstall') cmd.append('uninstall')
if module.params['version']: if module.params['version']:
cmd.extend([ '--version', module.params['version'] ]) cmd.extend([ '--version', module.params['version'] ])
@ -146,7 +157,7 @@ def install(module):
else: else:
major = None major = None
cmd = [ module.get_bin_path('gem', True) ] cmd = [ get_rubygems_path(module) ]
cmd.append('install') cmd.append('install')
if module.params['version']: if module.params['version']:
cmd.extend([ '--version', module.params['version'] ]) cmd.extend([ '--version', module.params['version'] ])
@ -160,7 +171,7 @@ def install(module):
if module.params['user_install']: if module.params['user_install']:
cmd.append('--user-install') cmd.append('--user-install')
else: else:
cmd.append('--no-user-install') cmd.append('--no-user-install')
cmd.append('--no-rdoc') cmd.append('--no-rdoc')
cmd.append('--no-ri') cmd.append('--no-ri')
cmd.append(module.params['gem_source']) cmd.append(module.params['gem_source'])
@ -170,6 +181,7 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( argument_spec = dict(
executable = dict(required=False, type='str'),
gem_source = dict(required=False, type='str'), gem_source = dict(required=False, type='str'),
include_dependencies = dict(required=False, default=True, type='bool'), include_dependencies = dict(required=False, default=True, type='bool'),
name = dict(required=True, type='str'), name = dict(required=True, type='str'),