Search code examples
mysqlnginxpuppetaugeas

Augeas in Puppet for mysql config failing


I'm currently developing some basic Puppet manifests and modules to install my application dependencies after my server has been deployed. It's a suite of basic stuff: -

  • OS -> Ubuntu 14.04 LTS
  • Nginx
  • PHP5-FPM
  • MySQL

Simple, right?

Everything is going pretty well for the most part; until I stumbled upon the ability to use Augeas to update the config files with my custom config items. I've set the PHP config items without any problems, as such:

augeas { 'php.ini':
    require => [
        Package['php5-fpm'],
        Package['libaugeas-ruby'],
    ],
    notify => Service['php5-fpm'],
    context => '/files/etc/php5/fpm/php.ini',
    changes => [
        'set PHP/cgi.fix_pathinfo 0',
    ],
}

This works just fine. No issues at all.

However, now I've come to the MySQL config file, I'm using the following (which was nearly a copy and paste job)

augeas { 'my.cnf':
    require => [
        Package['mysql-server'],
        Package['libaugeas-ruby'],
    ],
    notify => Service['mysql'],
    context => '/files/etc/mysql/my.cnf',
    changes => [
        'set mysqld/bind-address 0.0.0.0',
    ],
}

Unfortunately, this just isn't working. I looked at the augeas documentation regarding the lenses it ships with, and no issues. The following is the initial output from the Puppet apply command.

Error: /Stage[main]/Mysql/Augeas[my.cnf]: Could not evaluate: Save failed with return code false, see debug

The next logical step was, of course, to look at the debug information. Which was the following information in it.

Debug: Augeas[my.cnf](provider=augeas): sending command 'set' with params ["/files/etc/mysql/my.cnf/mysqld/bind-address", "0.0.0.0"]
Debug: Augeas[my.cnf](provider=augeas): Put failed on one or more files, output from /augeas//error:
Debug: Augeas[my.cnf](provider=augeas): /augeas/files/etc/mysql/my.cnf/error = put_failed
Debug: Augeas[my.cnf](provider=augeas): /augeas/files/etc/mysql/my.cnf/error/path = /files/etc/mysql/my.cnf
Debug: Augeas[my.cnf](provider=augeas): /augeas/files/etc/mysql/my.cnf/error/lens = /usr/share/augeas/lenses/dist/mysql.aug:39.13-.60:
Debug: Augeas[my.cnf](provider=augeas): /augeas/files/etc/mysql/my.cnf/error/message = Failed to match

Solution

  • Okay, so I've managed to get SOMETHING happening; but without probably fully understanding what's going on.

    Prior to asking the question above, I checked on the stock lenses available, and I saw both the PHP and MySQL lenses in the list at http://augeas.net/stock_lenses.html

    Neither of the links work that SHOULD be taking you through to the documentation - so, knowing that the PHP lens worked in a 'set section/setting value' type of way, I was assuming it's the same for the MySQL lens.

    Not exactly the case. The following syntax worked for me.

    augeas { 'my.cnf':
        require => [
            Package['mysql-server'],
            Package['libaugeas-ruby'],
        ],
        notify => Service['mysql'],
        context => '/files/etc/mysql/my.cnf',
        changes => [
            "set target[.='mysqld']/bind-address 0.0.0.0",
        ],
    }
    

    The following two resources were where I found the information. If anybody has any other documentation they can point me to, I'd be more than grateful.

    This gave me an idea of what the syntax probably should be: - https://www.adammalone.net/post/playing-augeas-fun-and-profit#.VXAEy1yqpBc

    And lines 62-65 of this script reaffirmed it for me: - https://github.com/example42/puppet-mysql/blob/master/manifests/augeas.pp