Check if Vagrant provisioning has been done

前端 未结 4 1097
忘了有多久
忘了有多久 2021-01-02 03:43

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)

4条回答
  •  渐次进展
    2021-01-02 04:20

    EDIT

    Was too fast to answer without trying it out first. The code in the link below may have worked in previous versions, however in 1.7.2 it will not work; You need to tweak it a bit:

    Vagrant.configure("2") do |config|
      if ARGV[0] == "ssh"
          config.ssh.username = 'other_username'
      end
    
      ...
    end
    

    original answer below

    Came here looking for an answer to the same question but none of existing ones were quite satisfying, so with a bit more digging I found this comment on github about how you could go around for your requirements:

    Vagrant.configure("2") do |config|
      if VAGRANT_COMMAND == "ssh"
          config.ssh.username = 'other_username'
      end
    
      ...
    end
    

    You just check if the vagrant command you're issuing is ssh then it will use the username you specified.

提交回复
热议问题