Provision Vagrant machine with Puppet using mysql module

Question:

I am trying to provision a Vagrant machine with Puppet using this mysql module .

Hola mundo is simple, it goes something like this:

class { '::mysql::server':
  root_password           => 'strongpassword',
  remove_default_accounts => true
}

However, my goal is that after doing Vagrant up the first time, a vagrant machine is built with a mysql server ready to be accessed from the host machine and accept connections from a defined user.

My attempt is the following:

class { '::mysql::server':
    root_password           => 'strongpass',
    remove_default_accounts => false,
    override_options => {
      mysqld => { bind-address => '0.0.0.0'} //permitir conexiones entrantes desde cualquier ip
    }
  }

//crear una base de datos llamada `mydb`, un usuario y asignarle una contraseña
  mysql::db { 'mydb':
      user     => 'admin',
      password => 'secret',
      host     => '192.168.33.1',
    }

//asignarle todos los permisos al usuario que acabamos de crear
  mysql_grant { 'admin@192.168.33.1/*.*':
    ensure     => 'present',
    options    => ['GRANT'],
    privileges => ['ALL'],
    table      => '*.*',
    user       => 'admin@192.168.33.1',
  }

To test that everything works as expected I do my tests like this:

  • Destroy vagrant machine if it already exists: vagrant destroy
  • Create the vagrant machine: vagrant up
  • Try to connect from MySQLWorkbench .

The weird thing is that, when trying to connect, the vagrant machine does not allow it but if I reprovision vagrant reload --provision then I can already connect and do any consulta from MySQLWorkbech . What am I doing wrong?

Answer:

I have been trying to replicate your problem and I ran into a couple of problems, apart from the plugin installation which is not as easy (at least on mac) as the documentation says.

The first thing was this ( taken from the module link ):

Restart: Whether the service should be restarted when things change. Valid values ​​are 'true', 'false'. Defaults to 'false'.

Then in your class of mysql::server Post:

restart => true,

That should be enough but if you want to be more sure of the order in which the blocks are executed add this in the mysql_grant part:

require => Class['::mysql::server']

That will ensure that this part runs until the previous one has run.

Luck!

Scroll to Top