# Install GVM and Grails

**URL:** <https://forum.ansible.com/t/install-gvm-and-grails/16901>\
**Category:** Ansible Project\
**Created:** [November 27, 2014, 5:18am UTC](https://forum.ansible.com/t/install-gvm-and-grails/16901 "2014-11-27T05:18:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tze\_Yang\_Ng](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@Tze\_Yang\_Ng](https://forum.ansible.com/u/Tze_Yang_Ng)\
**Post date:** [November 27, 2014, 5:18am UTC](https://forum.ansible.com/t/install-gvm-and-grails/16901/1 "2014-11-27T05:18:00Z")

</div>

Hi,

Trying to use ansible to install GVM and Grails, but can’t seem to make it work, anyone can help? Tried both shell and command, but none seem work.

- name: gvm | Install gvm prerequisites for Grails  
shell:  
curl -s [get.gvmtool.net](http://get.gvmtool.net) | bash  
sudo: yes  
tags: grails
- name: gvm set source | Set source for gvm  
shell:  
source “/home/vagrant/.gvm/bin/gvm-init.sh”  
sudo: yes  
tags: grails
- name: grails | install grails 2.3.7  
command:  
gvm install grails 2.3.7  
sudo: yes  
tags: grails

thanks.

---

<div class="post-metadata">

**Author:** ![Tze\_Yang\_Ng](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@Tze\_Yang\_Ng](https://forum.ansible.com/u/Tze_Yang_Ng)\
**Post date:** [November 30, 2014, 5:53pm UTC](https://forum.ansible.com/t/install-gvm-and-grails/16901/2 "2014-11-30T17:53:27Z")

</div>

Hi,

I managed to get further with the following:

- name: Set Home | Set to vagrant home before install Grails  
shell:  
cd /home/vagrant executable: /bin/bash  
sudo: no  
tags: grails

- name: gvm | Install gvm prerequisites for Grails  
shell:  
curl -s [get.gvmtool.net](http://get.gvmtool.net) | bash executable: /bin/bash  
sudo: no  
tags: grails

- name: gvm set source | Set source for gvm  
shell:  
source “/home/vagrant/.gvm/bin/gvm-init.sh” executable: /bin/bash  
sudo: no  
tags: grails

- name: grails | install grails 2.3.7  
shell:  
gvm install grails 2.3.7 executable: /bin/bash  
sudo: yes  
tags: grails

but it still failed at the last command: gvm install

TASK: [grails | install grails 2.3.7] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

failed: [default] =\> {“changed”: true, “cmd”: “gvm install grails 2.3.7”, “delta”: “0:00:00.003756”, “end”: “2014-11-30 17:43:51.951141”, “rc”: 127, “start”: “2014-11-30 17:43:51.947385”, “warnings”: }

stderr: /bin/bash: gvm: command not found

FATAL: all hosts have already failed – aborting

Any advice? Also how to press “y” at the end of the installation using playbook?  
thanks.

---

<div class="post-metadata">

**Author:** ![rxdazn](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rxdazn](https://forum.ansible.com/u/rxdazn)\
**Post date:** [November 30, 2014, 10:14pm UTC](https://forum.ansible.com/t/install-gvm-and-grails/16901/3 "2014-11-30T22:14:56Z")

</div>

Hi,

I was trying do install grails using gvm via ansible just like you today.  
After battling for a few hours with it, I ended up stumbling upon the discussion about getting a remote user’s environment using sudo where the last comment has a solution.

> So I now I rap all my shell calls in ‘bash -lc’ to get the remote user’s  
> environment set-uip properly. For instance :
> 
> - shell: cd; bash -lc “rbenv install {{ ruby\_version }}”

> **[Getting remote user environment with sudo](https://groups.google.com/g/ansible-project/c/cNgOQm-zF0U/m/vZ4ZBl8Z8QYJ)**

Here’s what my task file looks like for the grails part (it also has a solution for the prompting the gvm install grails confirmation dialog – just pipe it into yes see man yes):

# grails

- name: check if gvm is installed  
shell: test -d /usr/share/tomcat/.gvm && echo “yes” || echo “no”  
register: is\_gvm\_installed

- name: download gvm  
when: is\_gvm\_installed.stdout == “no”  
get\_url: url=[http://get.gvmtool.net](http://get.gvmtool.net) dest=/usr/share/tomcat/gvm\_install.sh  
remote\_user: tomcat

- name: install gvm  
when: is\_gvm\_installed.stdout == “no”  
command: bash /usr/share/tomcat/gvm\_install.sh  
sudo: yes  
sudo\_user: tomcat

- name: install grails

# probably not the most elegant way to have .bashrc sourced but that’ll do for now…

shell: bash -lc “gvm install grails | yes” executable=/bin/bash chdir=/usr/share/tomcat/  
sudo: yes  
sudo\_user: tomcat

Cheers,

rx

---

<div class="post-metadata">

**Author:** ![rxdazn](https://avatars.discourse-cdn.com/v4/letter/r/96bed5/32.png) [@rxdazn](https://forum.ansible.com/u/rxdazn)\
**Post date:** [November 30, 2014, 10:54pm UTC](https://forum.ansible.com/t/install-gvm-and-grails/16901/4 "2014-11-30T22:54:15Z")

</div>

About the yes command, I meant yes | gvm install grails rather than gvm install grails | yes, sorry!

---

<div class="post-metadata">

**Author:** ![Tze\_Yang\_Ng](https://avatars.discourse-cdn.com/v4/letter/t/e47c2d/32.png) [@Tze\_Yang\_Ng](https://forum.ansible.com/u/Tze_Yang_Ng)\
**Post date:** [December 1, 2014, 6:24am UTC](https://forum.ansible.com/t/install-gvm-and-grails/16901/5 "2014-12-01T06:24:03Z")

</div>

Hi,

Thanks!!! I wish i see this earlier, i ended up solve the issue just now and then your post showed up. Seem like there are some delay for the post to show-up. Just to share my solution as well for reference.

- name: gvm | Install gvm prerequisites for Grails  
shell:  
curl -s [get.gvmtool.net](http://get.gvmtool.net) | bash executable: /bin/bash  
sudo: no  
tags: grails

- name: gvm set source | Set source for gvm  
shell:  
source “/home/vagrant/.gvm/bin/gvm-init.sh” && yes | gvm install grails 2.3.7 executable: /bin/bash  
sudo: no  
tags: grails

---

<div class="post-metadata">

**Author:** ![Mirko\_Friedenhagen](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Mirko\_Friedenhagen](https://forum.ansible.com/u/Mirko_Friedenhagen)\
**Post date:** [December 1, 2014, 7:47am UTC](https://forum.ansible.com/t/install-gvm-and-grails/16901/6 "2014-12-01T07:47:11Z")

</div>

You could use the stat action as well which returns a handy exists boolean.  
[http://docs.ansible.com/stat\_module.html](http://docs.ansible.com/stat_module.html)

- stat: path=YOURPATH  
register: grailsinstalled

- other\_action: too  
when: grailsinstalled.stat.exists

Typing on my phone, so please excuse typos 🙂
