0

I'm exploring puppet on a standalone system and ran into a wall with copying a config file for MySQL. Using the manifest below, MySQL is installed but the my.cnf file is not copied over.

init.pp (hostname: dev_one.site.com)

class mysql {

  case $servername {
    "prod_one.site.com", "dev_one.site.com", "sandbox_one.site.com": {
      $conf_file    = 'my.cnf.one'
    }
    "prod_two.site.com", "dev_two.site.com", "sandbox_two.site.com": {
      $conf_file    = 'my.cnf.two'
    }
  }


  package { "mysql-server":
    ensure => present,
  }

  package { "mysql":
    ensure => present,
  }

  file { 'my.cnf':
    path    => '/etc/',
    ensure  => file,
    require => Package['mysql'],
    source  => "puppet:///modules/mysql/${conf_file}"
  }

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

}

And here is the result:

[root@dev_one manifests]# puppet apply --verbose ./init.pp 
Info: Applying configuration version '1379018555'
Notice: /Stage[main]/Mysql/Package[mysql-server]/ensure: created
Notice: /Stage[main]/Mysql/Service[mysqld]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]/Mysql/Service[mysqld]: Unscheduling refresh on Service[mysqld]
Notice: Finished catalog run in 14.34 seconds

[root@dev_one manifests]# ll /etc/my*
total 0

No errors, but my.cnf is not being copied. What am I doing wrong?

  • Where is servername being defined? – Zoredache Sep 12 '13 at 21:02
  • Shouldn't you be using hostname? That is actually set in facter unlike servername. – user160910 Sep 12 '13 at 21:13
2

First, where is $servername being set? That's not a standard fact, so for it to have content you'd need to have either a custom fact or manifest variable. Do you want to be using $clientcert or $fqdn instead?

On your file resource.. I would think that should be erroring out, but maybe not, since /etc/ exists.. the problem there is that the resource as declared is trying to manage /etc/ instead of /etc/my.cnf. Either declare the full path to the file in the resource name and omit the path parameter:

file { '/etc/my.cnf':

Or, have the path parameter be the full path to the file (then the name is irrelevant):

file { 'MySQL Config':
    path    => '/etc/my.cnf',

But.. I'd really recommend against having the logic of "which config file does this server get" hardcoded in your manifest. Use Hiera or node definitions with parameterized classes instead.

  • Updated my manifest with your second example - works fine now. – a coder Sep 12 '13 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.