Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

How to determine vagrant_machine_name from within VM #931

Closed
grasmash opened this issue Oct 18, 2016 · 5 comments
Closed

How to determine vagrant_machine_name from within VM #931

grasmash opened this issue Oct 18, 2016 · 5 comments
Labels

Comments

@grasmash
Copy link

grasmash commented Oct 18, 2016

I'd like to get the value of vagrant_machine_name while in the VM. Since I don't know what it may be for a given vm, I do not the path of the config.yml file (which I would otherwise parse for the value). I also cannot use hostname given the variability of domain name structure.

Is there an environmental variable or other means to determine this and other such ansible configuration values from within the VM?

@geerlingguy
Copy link
Owner

@grasmash - A few things that should be helpful:

  1. The root folder should always be mounted at /vagrant by default.
  2. You could add a shell provisioner in a Vagrantfile.local or overriding Vagrantfile that runs inside the guest and stores the machine name in a file somewhere (see this answer).
  3. IIRC, the hostname (determined by running hostname in the VM) should be the machine name...

@geerlingguy
Copy link
Owner

Also, you can check if /home/vagrant exists, or if vagrant is in /etc/passwd.

@grasmash
Copy link
Author

Ah, knowing that the mount point is always at /vagrant is good enough!

VAGRANT_MACHINE_NAME=$(grep vagrant_machine_name: /vagrant/box/config.yml | cut -d' ' -f 2).

Thanks!

@geerlingguy
Copy link
Owner

99% of the time—you can technically override it and not mount it, but people rarely do that :)

@geerlingguy
Copy link
Owner

99% of the time—you can technically override it and not mount it, but people rarely do that :)

Heh, /me slaps self after acquia/blt#1264

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants