Ask Your Question
0

mySQL - defining variables while using class

asked 2015-05-20 14:18:44 -0500

pup-master gravatar image

updated 2015-05-20 15:29:37 -0500

Trying to use "http://bitfieldconsulting.com/puppet-and-mysql-create-databases-and-users" for mySQL.

How do you define values for variables like sercet password, db name? That the class is going to use?

so far

[nodes.pp]

class mysql::server {

  package { "mysql-server": ensure => installed }
  package { "mysql": ensure => installed }

  service { "mysqld":
    enable => true,
    ensure => running,
    require => Package["mysql-server"],
  }

  file { "/var/lib/mysql/my.cnf":
    owner => "mysql", group => "mysql",
    source => "puppet:///fs/my.cnf",
    notify => Service["mysqld"],
    require => Package["mysql-server"],
  }

  file { "/etc/my.cnf":
    require => File["/var/lib/mysql/my.cnf"],
    ensure => "/var/lib/mysql/my.cnf",
  }


  exec { "set-mysql-password":
    unless => "mysqladmin -uroot -p$mysql_password status",
    path => ["/bin", "/usr/bin"],
    command => "mysqladmin -uroot password $mysql_password",
    require => Service["mysqld"],
  }


    define db( $user, $password ) {
      exec { "create-${name}-db":
        unless => "/usr/bin/mysql -uroot ${name}",
        command => "/usr/bin/mysql -uroot -e \"create database ${name};\"",
        require => Service["mysqld"],
      }

      exec { "grant-${name}-db":
        unless => "/usr/bin/mysql -u${user} -p${password} ${name}",
        command => "/usr/bin/mysql -uroot -e \"grant all on ${name}.* to ${user}@localhost identified by '$password';\"",
        require => [Service["mysqld"], Exec["create-${name}-db"]]
      }
   }

  define mysqldb( $user, $password ) {
    exec { "create-${name}-db":
      unless => "/usr/bin/mysql -u${user} -p${password} ${name}",
      command => "/usr/bin/mysql -uroot -p$mysql_password -e \"create database ${name}; grant all on ${name}.* to ${user}@localhost identified by '$password';\"",
      require => Service["mysqld"],
    }
  }



}

[site.pp]

node 'jira.oracle' { 

$mysql_password = 'secret'
$user = 'jira'
$password = 'secret'
$root_password = 'secret'
$remove_default_accounts = false
$dbname   = 'jiraDB'
$host     = 'localhost'


class {'mysql::server':} 
include mysql::db

   mysql_grant { 'jira@localhost/*.*':
      ensure     => 'present',
      options    => ['GRANT'],
      privileges => ['ALL'],
      table      => '*.*',
      user       => 'jira@localhost' ,
    }

    mysql_grant { 'root@localhost/*.*':
      ensure     => 'present',
      options    => ['GRANT'],
      privileges => ['ALL'],
      table      => '*.*',
      user       => 'root@localhost' ,
    }

    mysql_grant { 'jira@10.213.9.215/*.*':
      ensure     => 'present',
      options    => ['GRANT'],
      privileges => ['ALL'],
      table      => '*.*',
      user       => 'jira@10.213.9.215' ,
    }

    mysql_grant { 'root@10.213.9.215/*.*':
      ensure     => 'present',
      options    => ['GRANT'],
      privileges => ['ALL'],
      table      => '*.*',
      user       => 'root@10.213.9.215' ,
    }



}

[db.pp]

class mysql::db { 
 $user     = 'jira'
 $password = 'secret'
 $dbname   = 'jiraDB'
 $host     = 'localhost'
}

workbench attempt ends in:

jira ~]$ mysql -h 10.213.9.157 -u jira --password=secret jiraDB
ERROR 2003 (HY000): Can't connect to MySQL server on '10.213.9.157' (111)

localhost access works:

jira ~]$ mysql -h localhost  -u jira --password=secret jiraDB
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 567
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-05-20 17:58:28 -0500

GregLarkin gravatar image

First, don't use the code from that blog post. That is super-outdated, and all of that functionality has been replaced by a well-written and robust module you can download from the Puppet Forge: https://forge.puppetlabs.com/puppetlabs/mysql

Install that module and then start writing your Puppet code to use the classes in the module. The documentation on the module page on the Forge is top-notch, and you should find answers to all of your questions there. You can absolutely implement in Puppet what you are trying to do to configure MySQL.

edit flag offensive delete link more

Comments

Thank you for continued guidance. Will study them.

pup-master gravatar imagepup-master ( 2015-05-20 19:03:59 -0500 )edit

I created another post to branistorm http://ask.puppetlabs.com/question/17426/mysql-code-brainstorming/ Got it to work as that post is updated. Pretty close!!

pup-master gravatar imagepup-master ( 2015-05-21 13:58:54 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-05-20 14:18:44 -0500

Seen: 306 times

Last updated: May 20 '15