User Tools

Site Tools


технология_vagrant

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
технология_vagrant [2022/07/18 15:13]
val [Внутри Vagrantfile]
технология_vagrant [2024/03/11 19:00]
val [Multi-Machine Vagrant Environments]
Line 1: Line 1:
 ====== Технология Vagrant ====== ====== Технология Vagrant ======
 +
 +  * [[https://​ru.wikipedia.org/​wiki/​Vagrant|HashiCorp Vagrant]]
  
   * [[https://​www.vagrantup.com/​|Vagrant - Development Environments Made Easy]]   * [[https://​www.vagrantup.com/​|Vagrant - Development Environments Made Easy]]
Line 7: Line 9:
   * [[https://​oracle-base.com/​articles/​vm/​create-a-vagrant-base-box-virtualbox|Create a Vagrant Base Box (VirtualBox)]]   * [[https://​oracle-base.com/​articles/​vm/​create-a-vagrant-base-box-virtualbox|Create a Vagrant Base Box (VirtualBox)]]
  
-  * [[https://​www.vultr.com/​docs/​stop-dhcp-from-changing-resolve-conf/​|Stop DHCP From Changing resolv.conf]] 
  
 ===== Установка ===== ===== Установка =====
  
-  * [[https://​val.bmstu.ru/​unix/​HashiCorp/​vagrant_2.2.10_x86_64.msi]]+  ​* [[https://​hashicorp-releases.yandexcloud.net/​vagrant/​]] 
 + 
 +  ​* [[https://​val.bmstu.ru/​unix/​HashiCorp/​vagrant_2.2.10_x86_64.msi]] ​ 
 +  * [[http://​gate.isp.un/​unix/​HashiCorp/​vagrant_2.2.10_x86_64.msi]]  
 +  * Можно не перезагружать систему,​ но нужно перезапустить Cmder
  
 ===== Подготовка командной строки ===== ===== Подготовка командной строки =====
  
-==== win cmd === 
  
-<​code>​ 
-C:​\Users\Administrator>​ C:​\HashiCorp\Vagrant\bin\vagrant.exe 
-</​code>​ 
  
 ==== Cmder ==== ==== Cmder ====
  
   * [[Cmder]]   * [[Cmder]]
- 
 <​code>​ <​code>​
 λ bash λ bash
  
-$ alias vagrant=C:​\HashiCorp\Vagrant\bin\vagrant.exe $*+λ cd
 </​code>​ </​code>​
  
-==== mobaxterm ==== +
-<​code>​ +
-mobaxterm>​ alias vagrant=/​drives/​c/​HashiCorp/​Vagrant/​bin/​vagrant.exe $* +
-</​code>​+
  
  
Line 41: Line 38:
   * [[https://​oracle-base.com/​articles/​vm/​create-a-vagrant-base-box-virtualbox|Create a Vagrant Base Box (VirtualBox)]] + [[https://​bbs.archlinux.org/​viewtopic.php?​id=270005|[SOLVED] Latest sshd not accepting key algorithms]]   * [[https://​oracle-base.com/​articles/​vm/​create-a-vagrant-base-box-virtualbox|Create a Vagrant Base Box (VirtualBox)]] + [[https://​bbs.archlinux.org/​viewtopic.php?​id=270005|[SOLVED] Latest sshd not accepting key algorithms]]
   * [[https://​vagrantcloud.com/​debian/​bullseye64]]   * [[https://​vagrantcloud.com/​debian/​bullseye64]]
 +
 +  * [[https://​val.bmstu.ru/​unix/​HashiCorp/​ubuntu_20.04.box]]
 +  * [[http://​gate.isp.un/​unix/​HashiCorp/​ubuntu_20.04.box]]
 +
 +  * [[Переменные окружения]]
 +  * [[https://​stackoverflow.com/​questions/​19872591/​how-to-use-vagrant-in-a-proxy-environment|How to use vagrant in a proxy environment?​]]
  
 <​code>​ <​code>​
Line 49: Line 52:
 $ vagrant box list $ vagrant box list
  
-$ vagrant package --base ubuntu_20.04_03 --output /​c/​distrs/​ubuntu_20.04.box+### vagrant package --base ubuntu_20.04_03 --output /​c/​distrs/​ubuntu_20.04.box
  
 $ vagrant box add /​c/​distrs/​ubuntu_20.04.box --name specialist/​ubuntu20 $ vagrant box add /​c/​distrs/​ubuntu_20.04.box --name specialist/​ubuntu20
  
 $ vagrant box list $ vagrant box list
 +
 +$ ### vagrant box remove specialist/​ubuntu20
 </​code>​ </​code>​
  
-===== Создание VM =====+===== Создание и управление VM =====
  
 <​code>​ <​code>​
-$ mkdir ~/node1+$ mkdir ~/nodes
  
-$ cd ~/node1+$ cd ~/nodes
  
 $ vagrant init specialist/​ubuntu20 $ vagrant init specialist/​ubuntu20
Line 71: Line 76:
  
 $ vagrant up $ vagrant up
 +
 +$ ssh -p 2222 student@localhost
  
 $ vagrant ssh $ vagrant ssh
  
 $ vagrant global-status $ vagrant global-status
 +
 +$ vagrant global-status --prune
  
 $ vagrant halt $ vagrant halt
Line 81: Line 90:
 </​code>​ </​code>​
  
-===== Provision =====+===== Управление конфигурацией,​ использование переменных и Provision ​VM =====
  
   * [[https://​www.vagrantup.com/​docs/​provisioning|Provisioners in Vagrant]]   * [[https://​www.vagrantup.com/​docs/​provisioning|Provisioners in Vagrant]]
   * [[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 ====
  
 +  * [[https://​stackoverflow.com/​questions/​30820949/​print-message-after-booting-vagrant-machine-with-vagrant-up|Print message after booting vagrant machine with "​vagrant up"]]
 +  * [[https://​stackoverflow.com/​questions/​19648088/​pass-environment-variables-to-vagrant-shell-provisioner|Pass environment variables to vagrant shell provisioner]]
 +  * !!! Зрелищнее - по очереди,​ config и provision ​
 <​code>​ <​code>​
-λ npp Vagrantfile ​&+λ cat Vagrantfile
 </​code><​code>​ </​code><​code>​
 ... ...
 +X = "​13"​
 +
 Vagrant.configure("​2"​) do |config| Vagrant.configure("​2"​) do |config|
-... 
  
-  ​config.vm.network "​private_network",​ ip: "​192.168.X.210", virtualbox__intnet:​ false +### My config ### 
-  config.vm.hostname ​= "node1.corpX.un"+ 
 +  config.vm.post_up_message = "This is X: " + X 
 + 
 +  config.vm.hostname = "​node1.corp"​ + X + "​.un"​ 
 +  ​config.vm.network "​private_network", ​ 
 +    adapter: 2,  
 +    name: "​VirtualBox Host-Only Ethernet Adapter",​ 
 +    ​ip: "​192.168." + + ".201
 +  config.vm.provider "​virtualbox"​ do |vb| 
 +    vb.memory ​= "2048"​ 
 +    vb.cpus = "2" 
 + 
 +#    file_to_disk = config.vm.hostname + '​_disk2.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 
 +   
 +### /My config ### 
 + 
 +### My provision ###
   ​   ​
   config.vm.provision "​provision_once",​ type: "​shell",​ inline: <<​-SHELL   config.vm.provision "​provision_once",​ type: "​shell",​ inline: <<​-SHELL
Line 105: Line 141:
   SHELL   SHELL
  
-  config.vm.provision "​provision_onstart",​ run: "​always",​ type: "​shell",​ inline: <<​-SHELL+  config.vm.provision "​provision_onstart",​ run: "​always",​ type: "​shell", ​ 
 +    env: { 
 + "​X"​ => X, 
 + }, 
 +    ​inline: <<​-SHELL
  
     eval `route -n | awk '{ if ($8 ==\"​eth0\"​ && $2 != \"​0.0.0.0\"​) print \"​route del default gw \" $2; }'`     eval `route -n | awk '{ if ($8 ==\"​eth0\"​ && $2 != \"​0.0.0.0\"​) print \"​route del default gw \" $2; }'`
-    route add default gw 192.168.X.1+    route add default gw 192.168.$X.1
  
     cat <<EOF >/​etc/​resolv.conf     cat <<EOF >/​etc/​resolv.conf
-search ​corpX.un +search ​corp$X.un 
-nameserver 192.168.X.10+nameserver 192.168.$X.10
 EOF EOF
  
   SHELL   SHELL
 +
 +### /My provision ###
 +
 +...
  
 end end
-</​code>​ +</​code><​code>​ 
-<​code>​+λ vagrant validate 
 + 
 +λ vagrant up 
 +... 
 +==> default: Machine already provisioned ... 
 +... 
 +λ vagrant ssh 
 +$ date 
 λ vagrant reload --provision λ vagrant reload --provision
 +
 +λ vagrant ssh
 +$ date
 </​code>​ </​code>​
-==== С использованием внешних скриптов ====+ 
 +==== Provision с использованием внешних скриптов ==== 
 + 
 +  * [[https://​stackoverflow.com/​questions/​15461898/​passing-variable-to-a-shell-script-provisioner-in-vagrant|Passing variable to a shell script provisioner in vagrant]]
  
 <​code>​ <​code>​
-λ npp provision_once.sh ​&+λ touch provision_once.sh
 </​code><​code>​ </​code><​code>​
 +#!/bin/sh
 +
 +#echo '​root:​strongpassword'​ | chpasswd
 #sed -i '​s/​PasswordAuthentication no/​PasswordAuthentication yes/g' /​etc/​ssh/​sshd_config #sed -i '​s/​PasswordAuthentication no/​PasswordAuthentication yes/g' /​etc/​ssh/​sshd_config
 +#service ssh restart
 +
 +echo '​vagrant:​strongpassword'​ | chpasswd
 +
 +(echo '"​\e[A":​ history-search-backward';​ echo '"​\e[B":​ history-search-forward'​) >> /​etc/​inputrc
  
 timedatectl set-timezone Europe/​Moscow timedatectl set-timezone Europe/​Moscow
  
-apt-get update +apt update 
-#apt-get install -y net-tools+#apt install -y docker.io
 </​code><​code>​ </​code><​code>​
-λ npp provision_onstart.sh ​&+λ touch provision_onstart.sh
 </​code><​code>​ </​code><​code>​
-route add default gw 192.168.X.1+#​!/​bin/​bash 
 + 
 +X=$1 
 + 
 +echo "​$X"​ 
 + 
 +route add default gw 192.168."$X".1
  
-eval `route -n | awk '{ if ($8 =="​eth0"​ && $2 != "​0.0.0.0"​) print "route del default gw " $2; }'`+eval "$(route -n | awk '{ if ($8 =="​eth0"​ && $2 != "​0.0.0.0"​) print "route del default gw " $2; }')"
  
-echo -e 'search ​corpX.un\nnameserver 192.168.X.10' ​> /​etc/​resolv.conf+chattr -i /​etc/​resolv.conf 
 +echo -e "search ​corp$X.un\nnameserver 192.168.$X.10" ​> /​etc/​resolv.conf
 chattr +i /​etc/​resolv.conf chattr +i /​etc/​resolv.conf
  
 echo "​net.ipv4.ip_forward=1"​ > /​etc/​sysctl.d/​20-my-forward.conf && sysctl -p --system echo "​net.ipv4.ip_forward=1"​ > /​etc/​sysctl.d/​20-my-forward.conf && sysctl -p --system
 </​code><​code>​ </​code><​code>​
-λ npp Vagrantfile+λ cat Vagrantfile
 </​code><​code>​ </​code><​code>​
 ... ...
 +### My provision ###
 +
   config.vm.provision "​provision_once",​ type: "​shell",​ run: "​once",​ path: "​provision_once.sh"​   config.vm.provision "​provision_once",​ type: "​shell",​ run: "​once",​ path: "​provision_once.sh"​
-  ​config.vm.provision "​provision_onstart",​ type: "​shell",​ run: "​always",​ path: "​provision_onstart.sh"​+ 
 +  ​config.vm.provision "​provision_onstart",​ type: "​shell",​ run: "​always", ​ 
 +    args: X + " 2_arg 3_arg",​  
 +    ​path: "​provision_onstart.sh"​ 
 + 
 +### /My provision ###
 ... ...
 </​code><​code>​ </​code><​code>​
-λ vagrant ​provision --provision-with provision_once,​provision_onstart +vagrant@node1:~$ ls /vagrant/
-</code>+
  
 +vagrant@node1:​~$ shellcheck /​vagrant/​provision_once.sh
 +vagrant@node1:​~$ shellcheck /​vagrant/​provision_onstart.sh
  
 +λ vagrant provision --provision-with provision_once,​provision_onstart
 +
 +server# ssh vagrant@node1
 +</​code>​
  
-==== С использованием ansible ====+==== Provision с использованием ansible ====
  
   * Сервис Ansible [[Сервис Ansible#​Использование playbook]]   * Сервис Ansible [[Сервис Ansible#​Использование playbook]]
Line 164: Line 249:
 λ cat Vagrantfile λ cat Vagrantfile
 ... ...
-  config.vm.provision "​provision_docker",​ type: "​ansible_local",​ run: "always" do |ansible|+  config.vm.provision "​provision_docker",​ type: "​ansible_local",​ run: "once" do |ansible|
     ansible.playbook = "​provision_docker.yml"​     ansible.playbook = "​provision_docker.yml"​
   end   end
 +...
 </​code><​code>​ </​code><​code>​
-$ vagrant provision --provision-with provision_docker+time vagrant provision --provision-with provision_docker 
 +real    11m2,127s
 </​code>​ </​code>​
  
 ===== Multi-Machine Vagrant Environments ===== ===== 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>​ <​code>​
-$ mkdir ~/nodes+λ vagrant destroy
  
-$ cd ~/nodes+λ touch 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 ​init specialist/ubuntu20+Vagrant.configure("​2"​) do |config| 
 + 
 +### My config ### 
 +  nodes.each do |opts|  
 +    config.vm.define opts["​name"​] do |config| 
 +      config.vm.network "​private_network",​  
 +        adapter: 2,  
 +        name: "​VirtualBox Host-Only Ethernet Adapter",​ 
 +        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 status 
 + 
 +λ vagrant ssh node2 
 + 
 +λ vagrant halt node2 
 + 
 +λ vagrant destroy node1 
 + 
 +λ vagrant destroy -f 
 + 
 +λ cd ~/conf/​vagrant/​nodes 
 + 
 +λ nano Vagrantfile ​  #!!! set X 
 + 
 +λ cat provision_once.sh ​  # look passwords 
 + 
 +λ time vagrant up --parallel
 </​code>​ </​code>​
  
-==== Внутри Vagrantfile ​====+===== Дополнительные возможности ===== 
 + 
 + 
 + 
 +==== Еще варианты Multi-Machine Vagrant Environments ==== 
 + 
 +=== Внутри Vagrantfile ===
  
   * [[https://​www.vagrantup.com/​docs/​multi-machine|Multi-Machine]]   * [[https://​www.vagrantup.com/​docs/​multi-machine|Multi-Machine]]
Line 191: Line 348:
 Vagrant.configure("​2"​) do |config| Vagrant.configure("​2"​) do |config|
  
-  ​config.vm.define "node3" do |node1| +### My config ### 
-    node1.vm.network "​private_network",​ ip: "​192.168.X.210"+ 
 +  ​config.vm.define "node1" do |node1| 
 +    node1.vm.network "​private_network",​ ip: "​192.168.X.201"
   end   end
  
-  config.vm.define "node4" do |node2| +  config.vm.define "node2" do |node2| 
-    node2.vm.network "​private_network",​ ip: "​192.168.X.220"+    node2.vm.network "​private_network",​ ip: "​192.168.X.202"
   end   end
  
-  config.vm.define "node5" do |node3| +  config.vm.define "node3" do |node3| 
-    node3.vm.network "​private_network",​ ip: "​192.168.X.230"+    node3.vm.network "​private_network",​ ip: "​192.168.X.203"
   end   end
 +  ​
 +### /My config ###
 ... ...
 </​code>​ </​code>​
  
-==== С использованием структур данных ruby ====+=== С использованием структур данных ruby ===
  
   * [[https://​github.com/​hashicorp/​vagrant/​issues/​9200|Vagrant is assigning the same MAC to two different VMs?]]   * [[https://​github.com/​hashicorp/​vagrant/​issues/​9200|Vagrant is assigning the same MAC to two different VMs?]]
Line 213: Line 374:
     {     {
         :name => "​node1",​         :name => "​node1",​
-        :ip => "​192.168.X.210",+        :ip => "​192.168.X.201",
         :​vbox_config => [         :​vbox_config => [
             { "​--cpus"​ => "​2"​ },             { "​--cpus"​ => "​2"​ },
Line 221: Line 382:
     {     {
         :name => "​node2",​         :name => "​node2",​
-        :ip => "​192.168.X.220",+        :ip => "​192.168.X.202",
         :​vbox_config => [         :​vbox_config => [
             { "​--cpus"​ => "​2"​ },             { "​--cpus"​ => "​2"​ },
Line 229: Line 390:
     {     {
         :name => "​node3",​         :name => "​node3",​
-        :ip => "​192.168.X.230",+        :ip => "​192.168.X.203",
         :​vbox_config => [         :​vbox_config => [
             { "​--cpus"​ => "​2"​ },             { "​--cpus"​ => "​2"​ },
Line 239: Line 400:
 Vagrant.configure("​2"​) do |config| Vagrant.configure("​2"​) do |config|
  
 +### My config ###
   boxes.each do |opts|   boxes.each do |opts|
     config.vm.define opts[:name] do |config|     config.vm.define opts[:name] do |config|
Line 244: Line 406:
       config.vm.hostname = opts[:name]       config.vm.hostname = opts[:name]
  
-      ​config.vm.provider "​virtualbox"​ do | vb | +#      ​config.vm.provider "​virtualbox"​ do | vb | 
-        file_to_disk = opts[:name] + '​_2.vdi'​ +       ​file_to_disk = opts[:name] + '​_2.vdi'​ 
-        unless File.exist?​(file_to_disk) +       ​unless File.exist?​(file_to_disk) 
-          vb.customize ['​createhd',​ '​--filename',​ file_to_disk,​ '​--size', ​* 1024] +         ​vb.customize ['​createhd',​ '​--filename',​ file_to_disk,​ '​--size', ​* 1024] 
-        end +       end 
-        vb.customize ['​storageattach',​ :id, '​--storagectl',​ '​SATA ​Controller', '​--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
  
       opts[:​vbox_config].each do |hash|       opts[:​vbox_config].each do |hash|
Line 261: Line 423:
     end     end
   end   end
-  ... 
-end 
-</​code>​ 
-<​code>​ 
-λ vagrant up 
  
-λ vagrant ssh node2+### /My config ###
  
-λ vagrant destroy node3+  ...
  
-λ vagrant destroy -f+end
 </​code>​ </​code>​
  
-==== С использованием json ====+=== С использованием json ===
  
   * [[Формат JSON]]   * [[Формат JSON]]
   * [[https://​blog.scottlowe.org/​2016/​01/​18/​multi-machine-vagrant-json/​|Multi-Machine Vagrant Environments with JSON]]   * [[https://​blog.scottlowe.org/​2016/​01/​18/​multi-machine-vagrant-json/​|Multi-Machine Vagrant Environments with JSON]]
- 
-  addnodes -> nodes ?? 
-  node1 .. 3 ?? 
  
 <​code>​ <​code>​
-$ cat addnodes.json+λ npp nodes.json &
 </​code><​code>​ </​code><​code>​
 [ [
     {     {
-        "​name":​ "node3", +        "​name":​ "node1", 
-        "​ip":​ "​192.168.X.3",+        "​ip":​ "​192.168.X.201",
         "​vbox_config":​ [         "​vbox_config":​ [
-            { "​--cpus":​ "1" }, +            { "​--cpus":​ "2" }, 
-            { "​--memory":​ "1024" }+            { "​--memory":​ "2048" }
         ]         ]
     },     },
     {     {
-        "​name":​ "node4", +        "​name":​ "node2", 
-        "​ip":​ "​192.168.X.4",+        "​ip":​ "​192.168.X.202",
         "​vbox_config":​ [         "​vbox_config":​ [
-            { "​--cpus":​ "1" }, +            { "​--cpus":​ "2" }, 
-            { "​--memory":​ "1024" }+            { "​--memory":​ "2048" }
         ]         ]
     },     },
     {     {
-        "​name":​ "node5", +        "​name":​ "node3", 
-        "​ip":​ "​192.168.X.5",+        "​ip":​ "​192.168.X.203",
         "​vbox_config":​ [         "​vbox_config":​ [
-            { "​--cpus":​ "1" }, +            { "​--cpus":​ "2" }, 
-            { "​--memory":​ "1024" }+            { "​--memory":​ "2048" }
         ]         ]
     }     }
Line 315: Line 469:
 </​code><​code>​ </​code><​code>​
 require '​json'​ require '​json'​
-boxes = JSON.parse(File.read('​./​addnodes.json'​))+boxes = JSON.parse(File.read('​./​nodes.json'​))
  
 Vagrant.configure("​2"​) do |config| Vagrant.configure("​2"​) do |config|
 +
 +### My config ###
  
   boxes.each do |opts|   boxes.each do |opts|
     config.vm.define opts["​name"​] do |config|     config.vm.define opts["​name"​] do |config|
  
-      config.vm.network "​private_network",​ ip: opts["​ip"​]+      config.vm.network "​private_network",​ ip: opts["​ip"​]
-     virtualbox__intnet:​ true+
       config.vm.hostname = opts["​name"​]       config.vm.hostname = opts["​name"​]
- 
-#      config.vm.provider "​virtualbox"​ do | vb | 
-#        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 Controller',​ '​--port',​ 2, '​--device',​ 0, '​--type',​ '​hdd',​ '​--medium',​ file_to_disk] 
-#      end 
  
       opts["​vbox_config"​].each do |hash|       opts["​vbox_config"​].each do |hash|
Line 344: Line 491:
     end     end
   end   end
-#  config.vm.box = "​debian/​buster64"​ 
-  config.vm.box = "​debian/​bullseye64"​ 
  
-  ​config.vm.provision "​shell",​ inline: <<​-SHELL+### /My config ​###
  
-    sed -i '​s/​PasswordAuthentication no/​PasswordAuthentication yes/g' /​etc/​ssh/​sshd_config +...
-#    sed -i '​s/#​PermitRootLogin prohibit-password/​PermitRootLogin yes/g' /​etc/​ssh/​sshd_config +
-    systemctl restart sshd.service +
-    echo '​vagrant:​123'​ | chpasswd +
- +
-    apt-get update ​     +
-    apt-get install -y net-tools +
- +
-    cat <<EOF >/​etc/​resolv.conf +
-search corpX.un +
-nameserver 192.168.X.254 +
-EOF +
- +
-  SHELL +
- +
-  config.vm.provision "​shell",​ run: "​always",​ +
-    inline: "route add default gw 192.168.X.254"​ +
- +
-  config.vm.provision "​shell",​ run: "​always",​ +
-    inline: "eval `route -n | awk '{ if ($8 ==\"​eth0\"​ && $2 != \"​0.0.0.0\"​) print \"​route del default gw \" $2; }'​`"​+
  
 end end
-</​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>​
технология_vagrant.txt · Last modified: 2024/04/09 16:59 by val