1
resposta

Erro para subir terceira VM no mesmo vagrantfile

Olá,

Estou tentando subir uma vm com grafana, adionando mais um bloco no vagrant file. Sendo assim ficaram 3 vms no mesmo arquivo.

Porem ocorre o seguinte erro:

The machine with the name 'grafana' was not found configured for this Vagrant environment.

$script_mysql = <<-SCRIPT
  apt-get update && \
  apt-get install -y mysql-server-5.7 && \
  mysql -e "create user 'phpuser'@'%' identified by 'pass';"
SCRIPT

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"

  config.vm.define "mysqldb" do |mysql|
    mysql.vm.network "public_network", ip: "192.168.15.30", bridge: "wlp2s0b1"

    mysql.vm.provision "shell",
      inline: "cat /configs/id_bionic.pub >> .ssh/authorized_keys"
    mysql.vm.provision "shell", inline: $script_mysql
    mysql.vm.provision "shell",
      inline: "cat /configs/mysqld.cnf > /etc/mysql/mysql.conf.d/mysqld.cnf"
    mysql.vm.provision "shell", inline: "service mysql restart"

    mysql.vm.synced_folder "./configs", "/configs"
    mysql.vm.synced_folder ".", "/vagrant", disabled: true
  end

  config.vm.define "phpweb" do |phpweb|
    phpweb.vm.network "forwarded_port", guest: 8888, host: 8888
    phpweb.vm.network "public_network", ip: "192.168.15.31",bridge: "wlp2s0b1"

    phpweb.vm.provision "shell",
      inline: "apt-get update && apt-get install -y puppet"

    phpweb.vm.provision "puppet" do |puppet|
      puppet.manifests_path = "./configs/manifests"
      puppet.manifest_file = "phpweb.pp"
    end

    config.vm.define "grafana" do |grafana|
      grafana.vm.network "forwarded_port", guest: 3000, host: 3000
      grafana.vm.network "public_network", ip: "192.168.15.32",bridge: "wlp2s0b1"

      grafana.vm.provision "shell",
        inline: "apt-get update && apt-get install -y puppet"

      grafana.vm.provision "puppet" do |puppet|
        puppet.manifests_path = "./configs/manifests"
        puppet.manifest_file = "grafana.pp"
      end
    end
  end
end
1 resposta

Oi, Bruno. Tudo bem?

Pelo código que você mandou aqui, você colocou o bloco de configuração da máquina do grafana dentro do bloco do phpweb. Acredito que se você colocar o bloco alinhado com os outros dois que você definiu antes irá funcionar corretamente.

Ficaria dessa forma:

$script_mysql = <<-SCRIPT
  apt-get update && \
  apt-get install -y mysql-server-5.7 && \
  mysql -e "create user 'phpuser'@'%' identified by 'pass';"
SCRIPT

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"

  config.vm.define "mysqldb" do |mysql|
    mysql.vm.network "public_network", ip: "192.168.15.30", bridge: "wlp2s0b1"

    mysql.vm.provision "shell",
      inline: "cat /configs/id_bionic.pub >> .ssh/authorized_keys"
    mysql.vm.provision "shell", inline: $script_mysql
    mysql.vm.provision "shell",
      inline: "cat /configs/mysqld.cnf > /etc/mysql/mysql.conf.d/mysqld.cnf"
    mysql.vm.provision "shell", inline: "service mysql restart"

    mysql.vm.synced_folder "./configs", "/configs"
    mysql.vm.synced_folder ".", "/vagrant", disabled: true
  end

  config.vm.define "phpweb" do |phpweb|
    phpweb.vm.network "forwarded_port", guest: 8888, host: 8888
    phpweb.vm.network "public_network", ip: "192.168.15.31",bridge: "wlp2s0b1"

    phpweb.vm.provision "shell",
      inline: "apt-get update && apt-get install -y puppet"

    phpweb.vm.provision "puppet" do |puppet|
      puppet.manifests_path = "./configs/manifests"
      puppet.manifest_file = "phpweb.pp"
    end
  end

  config.vm.define "grafana" do |grafana|
      grafana.vm.network "forwarded_port", guest: 3000, host: 3000
      grafana.vm.network "public_network", ip: "192.168.15.32",bridge: "wlp2s0b1"

      grafana.vm.provision "shell",
        inline: "apt-get update && apt-get install -y puppet"

      grafana.vm.provision "puppet" do |puppet|
        puppet.manifests_path = "./configs/manifests"
        puppet.manifest_file = "grafana.pp"
      end
  end 
end

Espero ter ajudado. Bons estudos!