puppetlabs / puppetlabs-mysql

MySQL Puppet Module / Manifests + Types & Providers
Apache License 2.0
380 stars 796 forks source link

Add support for the Deferred function on mysql::db #1579

Open tuxmaster5000 opened 1 year ago

tuxmaster5000 commented 1 year ago

The mysql::db resource needs an password, but it can't received by the Deferred function of puppet. Sample code:

mysql::db { $foo:
    user      => $foo,
    charset   => $charset,
    password  => Sensitive(Deferred(FUNCTION ,[OPTIONS])),    
  }

The use of it fails with:

parameter 'password' expects a value of type String or Sensitive[String], got Sensitive[Object[{name => 'Deferred', attributes => {'name' => Pattern[/\A[$]?[a-z][a-z0-9]*(?:::[a-z][a-z0-9])\z/], 'arguments' => {type => Optional[Array], value => undef}}}]]

alexjfisher commented 1 year ago

Does your function return a Sensitive already (or could it be altered to)? I suspect the issue is you wrapping the Deferred in Sensitive. Also can you confirm your Puppet version?

tuxmaster5000 commented 1 year ago

I use puppet 8. The function will return an String. Without the Sensitive option, it will fails with:

Error: Could not set 'present' on ensure: invalid byte sequence in UTF-8 (file: /etc/puppetlabs/code/environments/production/modules/mysql/manifests/db.pp, line: 101)
Error: Could not set 'present' on ensure: invalid byte sequence in UTF-8 (file: /etc/puppetlabs/code/environments/production/modules/mysql/manifests/db.pp, line: 101)
Wrapped exception:
invalid byte sequence in UTF-8

For the char set utf8mb4 was chosen.

alexjfisher commented 1 year ago

Looking at the current version of the code, it looks like this should have worked. Can you confirm the module version you're using and also re-run with --debug --trace.

tuxmaster5000 commented 1 year ago

├── puppetlabs-mysql (v15.0.0) here the debug output: puppet.zip

alexjfisher commented 1 year ago

Looks like the database creation itself is failing before anything to do with the user's password.

I don't get the exact same error (which is probably mysql/mariadb version dependent), but I suspect the one I get highlights the problem.

COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'utf8mb4'

Try...

mysql::db { 'my_db':
  charset => 'utf8mb4',
  collate => 'utf8mb4_0900_ai_ci', # Or possibly 'utf8mb4_unicode_ci' depending on your mysql variant/version
}
tuxmaster5000 commented 1 year ago

Reading https://mariadb.com/kb/en/supported-character-sets-and-collations will shown that utf8mb4_general_ci will be the right. I have tried charset =>utf8mb4 with collate=>utf8mb4_general_ci. But the error are the same. I am using MariaDB 10.11.4. Here the last log: debug.zip On the command line, I can execute the last command before the error:

mysql -NBe "SHOW GRANTS FOR 'PUBLIC'@'';" ERROR 1141 (42000) at line 1: Für Benutzer 'PUBLIC' auf Host '%' gibt es keine solche Berechtigung