Check if Vagrant Server

43 views
Skip to first unread message

Phill Pafford

unread,
Jul 6, 2015, 12:33:01 PM7/6/15
to ansible...@googlegroups.com
Is there something I can check to see if the playbook is being executed on a vagrant server?

Example:

If vagrant run this additional role 

or

If vagrant skip this role

Thoughts on how I can do this?

Mischa ter Smitten

unread,
Jul 7, 2015, 3:16:15 AM7/7/15
to ansible...@googlegroups.com
We use

{% if ansible_virtualization_type == 'virtualbox' %}

Nigel Metheringham

unread,
Jul 7, 2015, 8:14:09 AM7/7/15
to ansible...@googlegroups.com
The virtualisation will change depending on what vagrant provider you use - and you people may use virtualbox without vagrant.

I suspect that there are a few signals that can be used to pick out vagrant - specifically I am thinking of ansible being run from vagrant provision rather than other access to a vagrant produced box:-
  • the ssh user is likely to be vagrant
  • there are probably some magic environment variables
  • the vagrant provided hosts file seems to have some magic in it

    Nigel.

7 July 2015 08:16
We use

{% if ansible_virtualization_type == 'virtualbox' %}

6 July 2015 17:33
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/44224986-111d-4c79-9c87-56f59353adc8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
[ Nigel Metheringham ------------------------------ ni...@dotdot.it ] 
[                 Ellipsis Intangible Technologies                  ]
 

Adrià

unread,
Jul 7, 2015, 9:01:36 AM7/7/15
to ansible...@googlegroups.com
On Tue, Jul 07, 2015 at 01:13:59PM +0100, Nigel Metheringham wrote:
> The virtualisation will change depending on what vagrant provider you use
> - and you people may use virtualbox without vagrant.
>
> I suspect that there are a few signals that can be used to pick out
> vagrant - specifically I am thinking of ansible being run from vagrant
> provision rather than other access to a vagrant produced box:-

I assume that below solution isn't the most elegant one, but what
about it?

- name: Check if I'm in a vagrant environment
stat: path=/vagrant/Vagrantfile
register: checkVagrant

- name: Let's do something if Vagrant is here
debug: msg="do something here"
when: checkVagrant.stat.exists

--
Adrià García-Alzórriz
0x09494C14
Una retirada a tiempo es una victoria.
signature.asc
Reply all
Reply to author
Forward
0 new messages