Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vagrant: Post task to remove vagrant user

I am provisioning a vagrant machine using ansible;

The question is whether it is possible to run some kind of post-processing (either in ansible or in any other form of vagrant provisioning) so as to remove the vagrant user at the end of the day (or at least disable it)?

Will this break the vagrant process/provisioning itself?

like image 698
pkaramol Avatar asked Oct 16 '25 11:10

pkaramol


1 Answers

This Vagrantfile demonstrates it's possible:

$script = <<-SCRIPT
useradd -m -p $(openssl passwd -1 password) user
usermod --expiredate 1 vagrant
sed -i "s/^PasswordAuthentication no$/PasswordAuthentication yes/" /etc/ssh/sshd_config 
service sshd restart
SCRIPT

VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = 'ubuntu/bionic64'
  config.vm.provision 'shell', inline: $script
end
like image 183
davejagoda Avatar answered Oct 19 '25 08:10

davejagoda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!