How we can create two database Using same credetial using Puppet

305 views
Skip to first unread message

Jithin Xavier

unread,
Mar 21, 2013, 6:37:35 AM3/21/13
to puppet...@googlegroups.com
Hello All,

I wanted to create two two MySQL database with same user credential using Puppet-MySQL. How can I achieve this? Please find my script below.

class mysql::vsdatabase {
 include mysql
 mysql::db { 'vidispine':
 user => 'user',
 password => 'user123',
 host => 'db.<hostname>.com',
}
}

How can I add another database here with same credential.(If I create different Class with different database and same credential I am getting below error.
root@demo:/mnt# puppet agent -t
info: Retrieving plugin
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/concat_basedir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/puppet_vardir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/root_home.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/iptables.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/pe_version.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/custom_auth_conf.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/facter_dot_d.rb
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Database_user[gxu...@db.demo.com] is already declared in file /etc/puppetlabs/puppet/modules/mysql/manifests/db.pp at line 62; cannot redeclare at /etc/puppetlabs/puppet/modules/mysql/manifests/db.pp:62 on node demo
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run
)

Thanks,
Jithin Xavier

llowder

unread,
Mar 21, 2013, 8:49:01 AM3/21/13
to puppet...@googlegroups.com


On Thursday, March 21, 2013 5:37:35 AM UTC-5, Jithin Xavier wrote:
Hello All,

I wanted to create two two MySQL database with same user credential using Puppet-MySQL. How can I achieve this? Please find my script below.

class mysql::vsdatabase {
 include mysql
 mysql::db { 'vidispine':
 user => 'user',
 password => 'user123',
 host => 'db.<hostname>.com',
}
}

Use a define[1] to create the database rather than a class. Classes are singletons, so you can only use them once per catalog (node). 

By using a define, you can pull the data from a wrapper class param or hiera, and then just call the define twice with different namevar but the same user & pass.


How can I add another database here with same credential.(If I create different Class with different database and same credential I am getting below error.
root@demo:/mnt# puppet agent -t
info: Retrieving plugin
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/concat_basedir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/puppet_vardir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/root_home.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/iptables.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/pe_version.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/custom_auth_conf.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/facter_dot_d.rb
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Database_user[gxu...@db.demo.com] is already declared in file /etc/puppetlabs/puppet/modules/mysql/manifests/db.pp at line 62; cannot redeclare at /etc/puppetlabs/puppet/modules/mysql/manifests/db.pp:62 on node demo
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run
)

Thanks,
Jithin Xavier


Calvin Walton

unread,
Mar 21, 2013, 9:02:07 AM3/21/13
to puppet...@googlegroups.com
On Thu, 2013-03-21 at 03:37 -0700, Jithin Xavier wrote:
> Hello All,
>
> I wanted to create two two MySQL database with same user credential using
> Puppet-MySQL. How can I achieve this? Please find my script below.
>
> class mysql::vsdatabase {
> include mysql
> mysql::db { 'vidispine':
> user => 'user',
> password => 'user123',
> host => 'db.<hostname>.com',
> }
> }
>
> How can I add another database here with same credential.(If I create
> different Class with different database and same credential I am getting
> below error.

The current git version of the mysql module has a fix for this error:
https://github.com/puppetlabs/puppetlabs-mysql/commit/1d6ca771d480e756cfdc5f84d73ef2d49f08ba38
but it has not yet been released. In the mean time, you can separately
use the underlying resources: (The mysql::db type is just a
convenience), just add additional 'database' and 'database_grant'
resources as needed:

database { 'vidispine':
ensure => 'present',
charset => 'utf-8',
provider => 'mysql',
require => Class['mysql::server'],
}

database_user { 'us...@example.com':
ensure => 'present',
password_hash => mysql_password('user123'),
provider => 'mysql',
require => Database['vidispine'],
}

database_grant { 'us...@example.com/vidispine':
privileges => 'all',
provider => 'mysql',
require => Database_user['us...@example.com'],
}

--
Calvin Walton <calvin...@kepstin.ca>

Jithin Xavier

unread,
Mar 25, 2013, 6:06:18 AM3/25/13
to puppet...@googlegroups.com
Thanks Calvin, It is working for me now. There is another issue which I noticed in Mysql is, I have set the root password in config.pp as below.

class mysql::config(
  $root_password     = 'Pa$$word!',
  $old_root_password = '',
  $bind_address      = $mysql::params::bind_address,
  $port              = $mysql::params::port,
  $etc_root_password = $mysql::params::etc_root_pass

and server.pp as

class mysql::server (
  $package_name     = $mysql::params::server_package_name,
  $package_ensure   = 'present',
  $service_name     = $mysql::params::service_name,
  $service_provider = $mysql::params::service_provider,
  $config_hash      = { 'root_password' => 'Pa$$word!'},
  $enabled          = true,
  $manage_service   = true
) inherits mysql::params {

issues which I am facing here is ,when I type mysql  command and enter without asking credetial its is going to mysql console. If trued with mysql -u root -p Pa$$word!, and its working as well..How can I restrict that mysql command enter to without credential to console?

Thanks,
Jithin

--
-Regards
Jithin Xavier

Felix Frank

unread,
Mar 25, 2013, 7:09:36 AM3/25/13
to puppet...@googlegroups.com
On 03/25/2013 11:06 AM, Jithin Xavier wrote:
> If trued with mysql -u root -p Pa$$word!, and its working as well

Hmm, that looks wrong. There must be no space between -p and the
password, otherwise the mysql command will interpret the latter as the
database to use, not the password.

Try "mysql -u root -p".

Anyway, it may be that there is a root account in your database with no
password. Try 'select user,host,password from mysql.user;'

HTH,
Felix

Jithin Xavier

unread,
Mar 25, 2013, 7:18:36 AM3/25/13
to puppet...@googlegroups.com
No, this is not my issue "mysql -u root -p" , My problem is ,if I type mysql command and enter,its going to mysql console with out giving me error,I am expecting some error here because I have set root credentials.





--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/HGWxMrC63nc/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To post to this group, send email to puppet...@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Felix Frank

unread,
Mar 25, 2013, 7:22:59 AM3/25/13
to puppet...@googlegroups.com
Then read again, please.

On 03/25/2013 12:18 PM, Jithin Xavier wrote:
> No, this is not my issue "mysql -u root -p" , My problem is ,if I type
> mysql command and enter,its going to mysql console with out giving me
> error,I am expecting some error here because I have set root credentials.
>
Reply all
Reply to author
Forward
0 new messages