# gem module and option user\_install: yes

**URL:** <https://forum.ansible.com/t/gem-module-and-option-user-install-yes/13351>\
**Category:** Ansible Project\
**Created:** [August 22, 2013, 6:03pm UTC](https://forum.ansible.com/t/gem-module-and-option-user-install-yes/13351 "2013-08-22T18:03:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jocelyn\_Jaubert](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jocelyn\_Jaubert](https://forum.ansible.com/u/Jocelyn_Jaubert)\
**Post date:** [August 22, 2013, 6:03pm UTC](https://forum.ansible.com/t/gem-module-and-option-user-install-yes/13351/1 "2013-08-22T18:03:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 23, 2013, 1:18am UTC](https://forum.ansible.com/t/gem-module-and-option-user-install-yes/13351/2 "2013-08-23T01:18:08Z")

</div>

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

Thanks!

---

<div class="post-metadata">

**Author:** ![Jocelyn\_Jaubert](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jocelyn\_Jaubert](https://forum.ansible.com/u/Jocelyn_Jaubert)\
**Post date:** [August 23, 2013, 6:13pm UTC](https://forum.ansible.com/t/gem-module-and-option-user-install-yes/13351/3 "2013-08-23T18:13:09Z")

</div>

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](http://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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 23, 2013, 10:01pm UTC](https://forum.ansible.com/t/gem-module-and-option-user-install-yes/13351/4 "2013-08-23T22:01:15Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Jocelyn\_Jaubert](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jocelyn\_Jaubert](https://forum.ansible.com/u/Jocelyn_Jaubert)\
**Post date:** [August 23, 2013, 10:44pm UTC](https://forum.ansible.com/t/gem-module-and-option-user-install-yes/13351/5 "2013-08-23T22:44:39Z")

</div>

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):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if major and major \< 2:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd.append('--include-dependencies')  
- if not module.params['user\_install']:  
+ if module.params['user\_install']:  
+ cmd.append('--user-install')  
+ else:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd.append('--no-user-install')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd.append('--no-rdoc')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd.append('--no-ri')

Thanks,  
Jocelyn

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [August 24, 2013, 5:01pm UTC](https://forum.ansible.com/t/gem-module-and-option-user-install-yes/13351/6 "2013-08-24T17:01:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jocelyn\_Jaubert](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jocelyn\_Jaubert](https://forum.ansible.com/u/Jocelyn_Jaubert)\
**Post date:** [August 24, 2013, 5:30pm UTC](https://forum.ansible.com/t/gem-module-and-option-user-install-yes/13351/7 "2013-08-24T17:30:57Z")

</div>

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:

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

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