Vagrant provision inline example

#Introduction

In this tutorial, How to use vagrant provision inline. Use inline to execute on the remote machine.

Vagrant provision inline example as below


Vagrant.configure("2") do |config|

  config.vm.define :ansible_controller do |ansible_controller|
    ansible_controller.vm.hostname = "ansible"
    ansible_controller.vm.box = "centos/6.5"
    ENV["LC_ALL"] = "en_US.UTF-8"
    config.ssh.insert_key = false
    ansible_controller.vm.network "private_network", ip: "192.168.3.10", :netmask => "255.255.255.0"
    ansible_controller.vm.provision "shell", inline: <<-SHELL
      echo "hello"
      echo "192.168.3.11 centos8" >> /etc/hosts
      groupadd -g 20000 gadmin
      useradd -d /home/huupv -u 9999 -m huupv
      echo -e "huupv\nhuupv\n" |  passwd huupv
      echo "huupv ALL = (root) NOPASSWD:ALL" | tee /etc/sudoers.d/huupv
      chmod 0440 /etc/sudoers.d/huupv
      su - huupv -c "echo |ssh-keygen -t rsa"
      SHELL
  end

  config.vm.define :centos do |centos|
    centos.vm.hostname = "centos8"
    centos.vm.box = "centos/8"
    ENV["LC_ALL"] = "en_US.UTF-8"
    config.ssh.insert_key = false
    centos.vm.network "private_network", ip: "192.168.3.11", :netmask => "255.255.255.0"
    centos.vm.provision "shell", inline: <<-SHELL
      echo "hello"
      groupadd -g 20000 gadmin
      useradd -d /home/huupv -u 9999 -m huupv
      echo -e "huupv\nhuupv\n" |  passwd huupv
      echo "huupv ALL = (root) NOPASSWD:ALL" | tee /etc/sudoers.d/huupv
      chmod 0440 /etc/sudoers.d/huupv
      useradd -m -d /home/user001 -s  /bin/bash   -g gadmin -u 8889  user001; echo -e "user001\nuser001\n"  |  passwd  user001
	  su - huupv -c "mkdir /home/huupv/.ssh"
      su - huupv -c "touch /home/huupv/.ssh/authorized_keys"
      su - huupv -c "chmod 600 /home/huupv/.ssh/authorized_keys"
      su - huupv -c "chmod 700 /home/huupv/.ssh"
    SHELL
  end
  end

Conclusion

You have use vagrant inline to execute on the remote machine. I hope will this your helpful. Thank you for reading the DevopsRoles page!

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.