Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Vagrant up ignorando provisionamento do mysql

Boa tarde,

estou tentando subir uma VM conforme a aula 4, entretanto não está sendo possível pois o mysql não é instalado.

Meu código:

$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.network "forwarded_port", guest: 80, host: 8087
    config.vm.network "public_network"

    config.vm.provision "shell", 
        inline: "cat / configs/id_bionic.pub >> .ssh/authorized_keys"

    config.vm.provision "shell", inline: $script_mysql

    config.vm.synced_folder "./configs/", "/configs"
    config.vm.synced_folder ".", "/vagrant", disable:true
end

Alternativamente tentei assim:


Vagrant.configure("2") do |config|

    config.vm.box = "ubuntu/bionic64"
    config.vm.network "forwarded_port", guest: 80, host: 8087
    config.vm.network "public_network"

    config.vm.provision "shell", 
        inline: "cat / configs/id_bionic.pub >> .ssh/authorized_keys"

    config.vm.provision "shell", inline: "apt-get update"
    config.vm.provision "shell", inline: "apt-get install -y mysql-server-5.7"
    config.vm.provision "shell", inline: "mysql -e create user 'phpuser'@'%' identified by 'pass';"

    config.vm.synced_folder "./configs/", "/configs"
    config.vm.synced_folder ".", "/vagrant", disable:true
end

O log que recebo é o seguinte:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/bionic64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/bionic64' version '20200930.0.0' is up to date...
==> default: Setting the name of the VM: bionic_default_1602012361997_76558
==> default: Clearing any previously set network interfaces...
==> default: Available bridged network interfaces:
1) Realtek PCIe GbE Family Controller
2) Hyper-V Virtual Ethernet Adapter
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
    default: Which interface should the network bridge to? 1
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 80 (guest) => 8087 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 5.2.42
    default: VirtualBox Version: 6.0
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/vitor/vagrant/bionic
    default: /configs => C:/Users/vitor/vagrant/bionic/configs
==> default: Running provisioner: shell...
    default: Running: inline script
    default: cat:
    default: /
    default: : Is a directory
    default: cat:
    default: configs/id_bionic.pub
    default: : No such file or directory
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

Onde estou errando?

1 resposta
solução!

A linha:

inline: "cat / configs/id_bionic.pub >> .ssh/authorized_keys"

Deveria ser:

inline: "cat /configs/id_bionic.pub >> .ssh/authorized_keys"

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software