How to make group changes take effect in a shell provisioner?

11 views
Skip to first unread message

Scott Wiersdorf

unread,
Dec 5, 2017, 5:30:11 PM12/5/17
to Vagrant
In a shell provisioner, I create a new group and then add the vagrant user to the new group:

config.vm.provision "shell", privileged: true, inline: <<-SHELL
  groupadd --force cvs
  usermod -a -G cvs vagrant
SHELL

In another shell provisioner, I need the vagrant user to belong to the 'cvs' group because a program that runs checks for it (something like this):

if `groups` =~ /cvs/ ...

but because Vagrant runs all provisioners through the same ssh connection to the vm, the changes haven't taken effect yet. If I log into the VM from another shell session, the group is present of course.

How can I make Vagrant "reload" or "restart" this shell without a full VM restart so that subsequent provisioners will see the changes to the vagrant user's groups?

Scott

Alvaro Miranda Aguilera

unread,
Dec 5, 2017, 6:32:19 PM12/5/17
to vagra...@googlegroups.com
can you change the script a bit?


agrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"

  config.vm.provision "shell", privileged: true, inline: <<-SHELL
    groups vagrant
    groupadd --force cvs
    usermod -a -G cvs vagrant
    groups vagrant
    exit
  SHELL

  config.vm.provision "shell", privileged: false, inline: <<-SHELL
    if [[ `exec sg cvs groups` =~ cvs ]] ; then echo yay ;else echo nay ;fi
    true
  SHELL

end
Reply all
Reply to author
Forward
0 new messages