# Check if Vagrant Server

**URL:** <https://forum.ansible.com/t/check-if-vagrant-server/18689>\
**Category:** Ansible Project\
**Created:** [July 6, 2015, 4:33pm UTC](https://forum.ansible.com/t/check-if-vagrant-server/18689 "2015-07-06T16:33:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phill\_Pafford](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@Phill\_Pafford](https://forum.ansible.com/u/Phill_Pafford)\
**Post date:** [July 6, 2015, 4:33pm UTC](https://forum.ansible.com/t/check-if-vagrant-server/18689/1 "2015-07-06T16:33:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Mischa\_ter\_Smitten](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@Mischa\_ter\_Smitten](https://forum.ansible.com/u/Mischa_ter_Smitten)\
**Post date:** [July 7, 2015, 7:16am UTC](https://forum.ansible.com/t/check-if-vagrant-server/18689/2 "2015-07-07T07:16:14Z")

</div>

We use

{% if ansible\_virtualization\_type == 'virtualbox' %}

---

<div class="post-metadata">

**Author:** ![Nigel\_Metheringham](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nigel\_Metheringham](https://forum.ansible.com/u/Nigel_Metheringham)\
**Post date:** [July 7, 2015, 12:13pm UTC](https://forum.ansible.com/t/check-if-vagrant-server/18689/3 "2015-07-07T12:13:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Adria](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@Adria](https://forum.ansible.com/u/Adria)\
**Post date:** [July 7, 2015, 12:45pm UTC](https://forum.ansible.com/t/check-if-vagrant-server/18689/4 "2015-07-07T12:45:44Z")

</div>

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

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

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