I am using Vagrant to deploy VMs for development. One of the requirements is that vagrant provision
creates a new user (done in a provisioning script I wrote) and then vagrant ssh
connects to the box as that user.
I cannot figure out how to tell if the box has been provisioned or not.
I see that the Vagrant provisioning code sets env[:provision_enabled]
if this run is supposed to be doing provisioning, so I thought I would be able to do something like this:
if env[:provision_enabled]
config.ssh.username = "#{data['ssh']['provision_username']}"
else
config.ssh.username = "#{data['ssh']['username']}"
end
The idea is that SSH connections for provisioning would use one connection and SSH connections for everything else would use the other.
However, env[:provision_enabled]
does not appear to be accessible in the Vagrantfile
.
Is there a way to do this?
vagrant up
config.ssh.username
is set, provisioning is done as that user. I want to keep provisioning as thevagrant
or theroot
user, but then switch to a user that was created during provisioning for all future SSH access.privileged (boolean) - Specifies whether to execute the shell script as a privileged user or not (sudo). By default this is "true".
So I guess you want to switch to an unprivileged user beyond provisioning?env[:provision_enabled]
is not accesible because the Vagrantfile is parsed before the environment is created. This information is available to provisioners and plugins, but not the Vagrantfile itself because of the load ordering. (see Vagrant issue #7043)