How can avoid the echo command run each time as I run "vagrant up --provision"

19 views
Skip to first unread message

Jason Yu

unread,
Mar 22, 2019, 7:19:54 PM3/22/19
to Vagrant
I have the following vagrantfile. If I run it for the  first time with "vagrant up", it works well. but when I ran it for the second time with "vagrant up --provision" it added the "export P4CONFIG=/vagrant/repos/.p4config"

it adds this line every time I run the command. Is there a way I can avoid it to be added twice?

Vagrant.configure("2") do |config|
## Specify the base box
config.vm.box = "xxxxx/vagrant_developer_box"
config.vm.box_version = "0.07"


## source .p4config file in .bashrc
config.vm.provision "shell", inline: 'echo "export P4CONFIG=/vagrant/repos/.p4config" >> /home/vagrant/.bashrc'
config.vm.provision "shell", inline: 'echo "After you ssh in, please modify the P4USER and P4PASSWD in your .p4config file" >> /etc/motd'

## Mount the user repos dir
config.vm.synced_folder '.', '/vagrant/repos', id: "vagrant-root",
owner: "vagrant",
group: "vagrant",
mount_options: ["dmode=775,fmode=664"]
config.vm.box_download_insecure = true

Brian Cain

unread,
Mar 22, 2019, 7:36:13 PM3/22/19
to vagra...@googlegroups.com
Hey there,

Provisioners have the option to define how often you want them to run. You can add a new key that will make it run only once:

config.vm.provision "shell", run: "once", inline: "echo 'hi'"


Thanks!

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/6d89ab57-a6c7-4bce-bbe6-d996dc1ffd23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Brian Cain

Alvaro Miranda Aguilera

unread,
Mar 25, 2019, 2:41:28 PM3/25/19
to vagra...@googlegroups.com
hello.

make your scripts idempotent.

just add those lines if you need them

ie

config.vm.provision "shell", inline: 'grep P4CONFIG /home/vagrant/.bashrc || echo "export P4CONFIG=/vagrant/repos/.p4config" >> /home/vagrant/.bashrc'

Thanks
Alvaro


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/6d89ab57-a6c7-4bce-bbe6-d996dc1ffd23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Alvaro

Jason Yu

unread,
Mar 29, 2019, 9:25:25 PM3/29/19
to vagra...@googlegroups.com
Thank you, I will try it out today.

Jason


For more options, visit https://groups.google.com/d/optout.
--

Thank you,

 

                              Jason Yu | Development Operations Engineer | Avery Products
                                  50 Pointe Drive, Brea, CA 92821 |(O)714.674.8422 J...@avery.com

Reply all
Reply to author
Forward
0 new messages