This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
технология_vagrant [2022/08/17 11:57] val [Provision с использованием внешних скриптов] |
технология_vagrant [2022/08/17 14:46] val [Внутри Vagrantfile] |
||
---|---|---|---|
Line 90: | Line 90: | ||
* [[https://www.vagrantup.com/docs/provisioning/basic_usage|Basic Usage of Provisioners]] | * [[https://www.vagrantup.com/docs/provisioning/basic_usage|Basic Usage of Provisioners]] | ||
* [[https://www.vagrantup.com/docs/networking/public_network|Vagrant public networks]] | * [[https://www.vagrantup.com/docs/networking/public_network|Vagrant public networks]] | ||
+ | |||
==== Внутри Vagrantfile ==== | ==== Внутри Vagrantfile ==== | ||
Line 110: | Line 111: | ||
config.vm.network "private_network", ip: "192.168." + X + ".201" | config.vm.network "private_network", ip: "192.168." + X + ".201" | ||
- | # config.vm.provider "virtualbox" do |vb| | + | config.vm.provider "virtualbox" do |vb| |
- | # vb.memory = "2048" | + | vb.memory = "2048" |
- | # vb.cpus = "2" | + | vb.cpus = "2" |
# file_to_disk = config.vm.hostname + '_disk2.vdi' | # file_to_disk = config.vm.hostname + '_disk2.vdi' | ||
Line 119: | Line 120: | ||
# end | # end | ||
# vb.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 2, '--device', 0, '--type', 'hdd', '--medium', file_to_disk] | # vb.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 2, '--device', 0, '--type', 'hdd', '--medium', file_to_disk] | ||
- | # end | + | |
+ | end | ||
| | ||
### /My config ### | ### /My config ### | ||
Line 157: | Line 159: | ||
λ vagrant reload --provision | λ vagrant reload --provision | ||
</code> | </code> | ||
+ | |||
==== Provision с использованием внешних скриптов ==== | ==== Provision с использованием внешних скриптов ==== | ||
Line 221: | Line 224: | ||
</code><code> | </code><code> | ||
$ vagrant provision --provision-with provision_docker | $ vagrant provision --provision-with provision_docker | ||
+ | </code> | ||
+ | |||
+ | ===== Multi-Machine Vagrant Environments ===== | ||
+ | |||
+ | * [[https://blog.scottlowe.org/2014/10/22/multi-machine-vagrant-with-yaml/|Multi-Machine Vagrant with YAML]] | ||
+ | * [[https://stackoverflow.com/questions/16708917/how-do-i-include-variables-in-my-vagrantfile|How do I include variables in my VagrantFile?]] | ||
+ | |||
+ | <code> | ||
+ | λ mkdir ~/nodes | ||
+ | |||
+ | λ cd ~/nodes | ||
+ | |||
+ | λ npp nodes.yaml & | ||
+ | </code><code> | ||
+ | - name: "node1" | ||
+ | ip: "201" | ||
+ | - name: "node2" | ||
+ | ip: "202" | ||
+ | - name: "node3" | ||
+ | ip: "203" | ||
+ | </code><code> | ||
+ | λ npp Vagrantfile | ||
+ | </code><code> | ||
+ | ... | ||
+ | require 'yaml' | ||
+ | nodes = YAML.load_file("./nodes.yaml") | ||
+ | |||
+ | Vagrant.configure("2") do |config| | ||
+ | |||
+ | ### My config ### | ||
+ | nodes.each do |opts| | ||
+ | config.vm.define opts["name"] do |config| | ||
+ | config.vm.network "private_network", ip: "192.168." + X + "." + opts["ip"] | ||
+ | config.vm.hostname = opts["name"] | ||
+ | | ||
+ | config.vm.provider :virtualbox do |vb| | ||
+ | # vb.name = opts["name"] | ||
+ | vb.memory = "2048" | ||
+ | vb.cpus = "2" | ||
+ | |||
+ | # file_to_disk = opts["name"] + '_2.vdi' | ||
+ | # unless File.exist?(file_to_disk) | ||
+ | # vb.customize ['createhd', '--filename', file_to_disk, '--size', 4 * 1024] | ||
+ | # end | ||
+ | # vb.customize ['storageattach', :id, '--storagectl', 'SATA', '--port', 2, '--device', 0, '--type', 'hdd', '--medium', file_to_disk] | ||
+ | |||
+ | end | ||
+ | end | ||
+ | end | ||
+ | ### /My config ### | ||
+ | ... | ||
+ | </code><code> | ||
+ | λ vagrant up node1 | ||
+ | |||
+ | λ vagrant up | ||
+ | |||
+ | λ vagrant ssh node2 | ||
+ | |||
+ | λ vagrant destroy node3 | ||
+ | |||
+ | λ vagrant destroy -f | ||
+ | </code> | ||
+ | |||
+ | ===== Дополнительные возможности ===== | ||
+ | |||
+ | |||
+ | |||
+ | ==== Использование синхронизируемых каталогов ==== | ||
+ | |||
+ | <code> | ||
+ | λ cat Vagrantfile | ||
+ | </code><code> | ||
+ | ... | ||
+ | # config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: ".git/" | ||
+ | ... | ||
+ | </code><code> | ||
+ | λ npp SomeFile | ||
+ | ... | ||
+ | |||
+ | λ vagrant rsync | ||
+ | |||
+ | λ vagrant ssh | ||
+ | |||
+ | vagrant@node3:~$ ls /vagrant/ | ||
+ | </code><code> | ||
+ | ... | ||
+ | Vagrantfile | ||
+ | ... | ||
+ | SomeFile | ||
+ | ... | ||
</code> | </code> | ||
Line 392: | Line 485: | ||
end | end | ||
- | </code> | ||
- | <code> | ||
- | λ vagrant up node1 | ||
- | |||
- | λ vagrant up | ||
- | |||
- | λ vagrant ssh node2 | ||
- | |||
- | λ vagrant destroy node3 | ||
- | |||
- | λ vagrant destroy -f | ||
- | </code> | ||
- | |||
- | ===== Дополнительные возможности ===== | ||
- | |||
- | |||
- | |||
- | ==== Использование синхронизируемых каталогов ==== | ||
- | |||
- | <code> | ||
- | λ cat Vagrantfile | ||
- | </code><code> | ||
- | ... | ||
- | # config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: ".git/" | ||
- | ... | ||
- | </code><code> | ||
- | λ npp SomeFile | ||
- | ... | ||
- | |||
- | λ vagrant rsync | ||
- | |||
- | λ vagrant ssh | ||
- | |||
- | vagrant@node3:~$ ls /vagrant/ | ||
- | </code><code> | ||
- | ... | ||
- | Vagrantfile | ||
- | ... | ||
- | SomeFile | ||
- | ... | ||
</code> | </code> |