diff options
| author | Eduardo Morais <eduardoromorais@gmail.com> | 2025-08-27 15:00:26 -0300 |
|---|---|---|
| committer | Eduardo Morais <eduardoromorais@gmail.com> | 2025-08-27 15:00:26 -0300 |
| commit | 87993c76db7ef790cfe58a6b3c71412f33a77936 (patch) | |
| tree | 59a18eaf41d117c06e6afd08431abfb5a3a19b21 | |
| parent | 85e4714c53b662c45a1f6ee4b6cb0089ad29cc7b (diff) | |
| download | pyvyos-87993c76db7ef790cfe58a6b3c71412f33a77936.tar.gz pyvyos-87993c76db7ef790cfe58a6b3c71412f33a77936.zip | |
Fix/9910428810 - Atualizando Vagrantfile, remoção de dependencia dotenv, atualizacao .env.example
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | vagrant/.env.example | 9 | ||||
| -rw-r--r-- | vagrant/VAGRANT.md | 10 | ||||
| -rw-r--r-- | vagrant/Vagrantfile | 91 |
4 files changed, 48 insertions, 64 deletions
@@ -165,4 +165,4 @@ packer/ *.code-workspace .env dev/ - +.idea diff --git a/vagrant/.env.example b/vagrant/.env.example index 36bebf8..905f259 100644 --- a/vagrant/.env.example +++ b/vagrant/.env.example @@ -1,13 +1,12 @@ - # vyos https api key -VYDEVICE_APIKEY=your_api_key +VYDEVICE_APIKEY="your_api_key" # vyos network interface VYDEVICE_IP=192.168.56.10 VYDEVICE_NETMASK=255.255.255.0 +VYDEVICE_HTTPS_PORT=443 # HOST_IP is the ip address of the host machine of the virtualbox # use your windows network interface for virtualbox running on windows host and using wsl2 for vagrant -HOST_IP=192.168.0.114 -# or use 127.0.0.1, virtualbox running on linux host or windows host -# HOST_IP=127.0.0.1
\ No newline at end of file +VYDEVICE_HOST_IP=192.168.0.114 +# use 127.0.0.1, virtualbox running on linux host or windows host diff --git a/vagrant/VAGRANT.md b/vagrant/VAGRANT.md index 69a28f5..e6312e2 100644 --- a/vagrant/VAGRANT.md +++ b/vagrant/VAGRANT.md @@ -13,7 +13,6 @@ If you want to only use pyvyos you dont need to install vagrant 3. Install Vagrant plugins ``` vagrant plugin install vagrant-vyos -vagrant plugin install vagrant-dotenv ``` 4. Install mkisofs @@ -21,11 +20,16 @@ vagrant plugin install vagrant-dotenv sudo apt install genisoimage ``` -5. Run vagrant up +5. Create .env file +``` +mv .env.example .env +``` + +6. Run vagrant up ``` vagrant up ``` -6. Run vagrant ssh +7. Run vagrant ssh ``` vagrant ssh ``` diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile index 1b20c97..9ac7606 100644 --- a/vagrant/Vagrantfile +++ b/vagrant/Vagrantfile @@ -1,61 +1,42 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -# Documentation: -# - read VAGRANT.md -# - need vagrant plugin install vagrant-vyos +env_vars = File.readlines('.env').each_with_object({}) do |line, hash| + next if line.strip.empty? || line.start_with?('#') + key, value = line.strip.split('=', 2) + hash[key.strip] = value.strip.gsub(/(^['"]|['"]$)/, '') +end + +HTTPS_PORT = env_vars['VYDEVICE_HTTPS_PORT'] +API_KEY = env_vars['VYDEVICE_APIKEY'] +NETMASK = env_vars['VYDEVICE_NETMASK'] +VYOS_VM_IP = env_vars['VYDEVICE_IP'] +VYOS_VM_HOST_IP = env_vars['VYDEVICE_HOST_IP'] + + +$script = <<-SHELL + cfg=/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper + $cfg begin + $cfg set service https api debug + $cfg set service https api keys id apikey key #{API_KEY} + $cfg set service https listen-address $1 + $cfg set service https port #{HTTPS_PORT} + $cfg commit + $cfg end +SHELL Vagrant.configure("2") do |config| - # enable the environment variables - # need vagrant plugin install vagrant-dotenv - config.env.enable - - # vm to deploy tests - config.vm.define "pyvyos" do |pyvyos| - pyvyos.vm.box = "vyos/current" - pyvyos.vm.hostname = "pyvyos" - - # network configuration of eth1 - pyvyos.vm.network "private_network", ip: ENV['VYDEVICE_IP'], netmask: ENV['VYDEVICE_NETMASK'] - pyvyos.ssh.host = ENV['HOST_IP'] - - # nat port forwarding - pyvyos.vm.network "forwarded_port", guest: 443, host: 8433, id: "https", auto_correct: true, protocol: "tcp", host_ip: ENV['HOST_IP'] - pyvyos.vm.network "forwarded_port", guest: 22, host: 2022, id: "ssh", auto_correct: true, protocol: "tcp", host_ip: ENV['HOST_IP'] - - # ssh configuration default username and password of vyos/current is vyos / vyos - # if you want to change the default password, you can change in provision script - # also, you can disable ssh password in provision script and use only ssh key - pyvyos.ssh.username = "vyos" - pyvyos.ssh.password = "vyos" - - # vagrant will insert the ssh key in the vm automatically, so password authentication after - # first boot is not necessary - pyvyos.ssh.insert_key = true - - # mkdir /opt/vyatta/config/certs - # chmod 0700 /opt/vyatta/config/certs + # Device VyOS + config.vm.define "pyvyos_device" do |pyvyos| + pyvyos.vm.box = "vyos/current" + pyvyos.vm.hostname = "pyvyos-device-2" + pyvyos.vm.network "private_network", ip: VYOS_VM_IP , netmask: NETMASK + pyvyos.ssh.host = VYOS_VM_HOST_IP - # generate pki certificate self-signed file /opt/vyatta/config/certs/certself - # set pki certificate certself certificate "$(cat /opt/vyatta/config/certs/certself.pem | tail -n +2 | head -n -1 | tr -d '\n')" - # set pki certificate certself private key "$(cat /opt/vyatta/config/certs/certself.key | tail -n +2 | head -n -1 | tr -d '\n')" + pyvyos.vm.network "forwarded_port", guest: 443, host: 8433, id: "https", auto_correct: true, protocol: "tcp", host_ip: VYOS_VM_HOST_IP + pyvyos.vm.network "forwarded_port", guest: 22, host: 2022, id: "ssh", auto_correct: true, protocol: "tcp", host_ip: VYOS_VM_HOST_IP - # generate pki ca file /opt/vyatta/config/certs/certca - # set pki ca certca certificate "$(cat /opt/vyatta/config/certs/certca.pem | tail -n +2 | head -n -1 | tr -d '\n')" - # set pki ca certca private key "$(cat /opt/vyatta/config/certs/certca.key | tail -n +2 | head -n -1 | tr -d '\n')" + pyvyos.ssh.username = "vyos" + pyvyos.ssh.password = "vyos" + pyvyos.ssh.insert_key = false + pyvyos.vm.provision "shell", inline: $script, args: [VYOS_VM_IP] - # shell script to provision the vyos vm - pyvyos.vm.provision "shell", inline: <<-SHELL - #!/bin/vbash - source /opt/vyatta/etc/functions/script-template - configure - set service https listen-address '#{ENV['VYDEVICE_IP']}' - set service https api keys id 'apikey' key '#{ENV['VYDEVICE_APIKEY']}' - set service https api debug - set service https api strict - commit - save - exit - SHELL - end end +end
\ No newline at end of file |
