Provisioning Shell problem multiple scripts

78 views
Skip to first unread message

Juan Carlos Pérez Pardo

unread,
Mar 30, 2016, 9:56:28 AM3/30/16
to Vagrant

Hi there!

I was thinking is maybe is possible to use several shell scripts to provision the machine.

I mean, instead to have a big one, use different ones, with the concept from configuration management.

I have a nodes. json definition as this one:

{

  "nodes": {

    "vagrant.domain": {

      ":ip": "192.168.32.5",

      "ports": [],

      ":memory": 2048,

      "bootstrap": ["bootstrap-hosts.sh","bootstrap-centos.sh"]

    }

  }

}

 

And I was trying something like this in my vagrant file ….

# vi: set ft=ruby :

 

# Builds Puppet Master and multiple Puppet Agent Nodes using JSON config file

# Author: Gary A. Stafford

 

# read vm and chef configurations from JSON files

nodes_config = (JSON.parse(File.read("nodes.json")))['nodes']

 

VAGRANTFILE_API_VERSION = "2"

 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "centos/7"

 

  nodes_config.each do |node|

    node_name   = node[0] # name of node

    node_values = node[1] # content of node

 

    config.vm.define node_name do |config|   

      # configures all forwarding ports in JSON array

      ports = node_values['ports']

      ports.each do |port|

        config.vm.network :forwarded_port,

          host:  port[':host'],

          guest: port[':guest'],

          id:    port[':id'],

          auto_correct: true

      end

 

      config.vm.hostname = node_name

      config.vm.network :private_network, ip: node_values[':ip']

 

      config.vm.provider :virtualbox do |vb|

        vb.customize ["modifyvm", :id, "--memory", node_values[':memory']]

        vb.customize ["modifyvm", :id, "--name", node_name]

      end

 

      # config.vm.provision :shell, :path => node_values[':bootstrap']

      valores = node_values['bootstrap']

      valores.each do |v|

        #puts v.upcase

        config.vm.provision :shell, path=> v.upcase

      end

    end

  end

end

 

Thanks!

 

 

 

Alvaro Miranda Aguilera

unread,
Mar 30, 2016, 10:57:57 PM3/30/16
to vagra...@googlegroups.com
Hello,

There are lots of example in the internet around what you can do. Basically because Vagrantfile is ruby :D

ie.


Have a look at the end there is a link to a github project.

If you check projects that distribute vagrantfiles with them, you will find nice examples of things you can incorporate later.

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/1bea458f-88df-44eb-8f5c-feff5d2f4bf9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Juan Carlos Pérez Pardo

unread,
Mar 31, 2016, 4:59:11 AM3/31/16
to vagra...@googlegroups.com

Wow looks really interesting! I guess that is I was looking for, the way to put some scripts there…

"scripts": [

                "update.sh",

                "supervisor.sh",

                "git.sh",

                "node.sh",

                "global_node_modules.sh",

                "ssh.sh"

            ]

 

I guess that part in addition with the libraries, specially the config_virtualbox


   
# Run provisioning scripts

    # Global

    server["host_scripts"].each do |script, key|

        instance.vm.provision :host_shell do |host_shell|

            host_shell.inline = './host_scripts/' + script

        end

    end

So thanks a million for your reply!

 

Gracias!

JC


You received this message because you are subscribed to a topic in the Google Groups "Vagrant" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vagrant-up/CNoO9toLiJo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0ezA-ajD7Vvvc22KOoizQ6Ke420VAoi_NXBUeXAU%3DnTA6w%40mail.gmail.com.

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



--
-----------------------------------------------------------
Juan Carlos Pérez
-----------------------------------------------------------
-----------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages