gem module and option user_install: yes

Hi,

According to the documentation, gem module accepts an option to install gems in home directory (user_install: yes). It doesn’t seem to work as described, because this module launches “gem” commande without adding --user-install, which means that they are installed in /var/lib/gems. Should the module add this option ?

Currently, the module has the following code:

cmd = [ module.get_bin_path(‘gem’, True) ]

if not module.params[‘user_install’]:
cmd.append(‘–no-user-install’)

I can provide a patch to add --user-install in the opposite case if this is the recommended way.

Or am I missing something in how I should configure gem or .gemrc ?

For information, I’m using ruby1.9.1 from Debian Wheezy.

Thanks,
Jocelyn

Can you share the line you are using from your ansible playbook as well as the output from running it in --verbose mode ?

Thanks!

I’m using this:

  • name: install gems
    gem: user_install=yes name=“{{ item }}” state=present
    sudo: yes
    sudo_user: jocelyn
    with_items:
  • rack

The command output:

TASK: [install gems] **********************************************************
failed: [osm3.openstreetmap.fr] => (item=rack) => {“cmd”: [“/usr/bin/gem”, “install”, “–include-dependencies”, “–no-rdoc”, “–no-ri”, “rack”], “failed”: true, “item”: “rack”, “rc”: 1}
stderr: ERROR: While executing gem … (Errno::EACCES)
Permission denied - /var/lib/gems

stdout: INFO: gem install -y is now default and will be removed
INFO: use --ignore-dependencies to install only the gems you list

msg: ERROR: While executing gem … (Errno::EACCES)
Permission denied - /var/lib/gems

FATAL: all hosts have already failed – aborting

Thanks,
Jocelyn

So in Ansible 1.3 the module adds “–no-user-install” when user_install is set to no.

user_install=yes is the default.

Can you please check the version of Ansible you are using and let me know if you see a problem in 1.3?

I seem to recall this feature was added recently but Ansible does yell about invalid arguments so thinking an older version might have had a bug and want to be sure.

Thanks!

Le 24/08/2013 00:01, Michael DeHaan a �crit :

So in Ansible 1.3 the module adds "--no-user-install" when user_install
is set to no.

user_install=yes is the default.

Can you please check the version of Ansible you are using and let me
know if you see a problem in 1.3?

I'm using ansible 1.3, and gem 1.8.23. I don't see anything on gem
documentation suggesting that --user-install is the default value, so
I'm surprised that gem module doesn't add this.

I'm suggesting the following patch in fact:

diff --git a/library/packaging/gem b/library/packaging/gem
index 889f510..762bf57 100644
--- a/library/packaging/gem
+++ b/library/packaging/gem
@@ -157,7 +157,9 @@ def install(module):
     else:
         if major and major < 2:
             cmd.append('--include-dependencies')
- if not module.params['user_install']:
+ if module.params['user_install']:
+ cmd.append('--user-install')
+ else:
         cmd.append('--no-user-install')
     cmd.append('--no-rdoc')
     cmd.append('--no-ri')

Thanks,
Jocelyn

If you can verify that that command switch (in fact both of them) is there in all gem versions I’m fine with this, and please send me a patch.

Otherwise we may have to determine if that flag is appropriate and send it based on the version of the tool. I’ll yield to experts here.

I wouldn’t be surprised if the default in the CLI changed at some point.

Le 24/08/2013 19:01, Michael DeHaan a �crit :

If you can verify that that command switch (in fact both of them) is
there in all gem versions I'm fine with this, and please send me a patch.

Otherwise we may have to determine if that flag is appropriate and send
it based on the version of the tool. I'll yield to experts here.

I wouldn't be surprised if the default in the CLI changed at some point.

According to RubyGem changelog, the command option --user-install was
available at least on version 1.3.0 (2008-09-25). I'm not sure if it was
present earlier.

On version 1.3.7 (2010-05-13), default was changed from --user-install
to --no-user-install:

=== 1.3.7 / 2010-05-13

[...]

New features:

[...]
  * --user-install is no longer the default. If you really liked it, see
    Gem::ConfigFile to learn how to set it by default. (This change was
made
    in 1.3.6)
[...]

I'm sending the patch through a pull request on github.