Check if Vagrant Server

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?

We use

{% if ansible_virtualization_type == 'virtualbox' %}

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.

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