Vagrant up or Kitchen test without sudo passwords

Almost every time I run vagrant up or kitchen test I’m required to enter my sudo password so that vagrant can mount nfs-shares or can access the hosts file. It got a bit annoying to start provisioning a new vagrant box, walk a way to grab something to drink and come back to see the prompt waiting for my sudo password. To fix this I found this little snippet which can be added to your sudoers file. It will allow NFS and the vagrant-hosts-updater plugin to elevate their permissions without entering your password each time.

Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD = /sbin/nfsd restart
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /usr/bin/sed -E -e /*/ d -ibak /etc/exports
Cmnd_Alias VAGRANT_HOSTSUPDATER_ADD = /bin/sh -c 'echo "*" >> /etc/hosts'
Cmnd_Alias VAGRANT_HOSTSUPDATER_REMOVE = /bin/sed -i -e  "*" d  /etc/hosts
%admin ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD, VAGRANT_EXPORTS_REMOVE, VAGRANT_HOSTSUPDATER_ADD, VAGRANT_HOSTSUPDATER_REMOVE
comments powered by Disqus