Nicolas
Nicolas

Reputation: 1474

Puppet and Mysql 5.5

The Background

I am using Centos 6.5 with Puppet 3.7.3.

I've installed the module puppetlabs-mysql v3.1.0

Centos 6.5 comes with MySql 5.1.73 installed by default. What I'd like to achieve is to upgrade that version via Puppet to 5.5.40, using the module described above

The initial Solution

Well, I couldn't find a proper solution to do this. The official documentation only tells how to configure the puppet manifest in order to have MySql installed, not taking into account the version. That doesn't suit me because the version remains unchanged after running the puppet agent.

package { "MySQL-client": ensure => installed }

Solution #1 found on Internet Forums

Found here.

package {
    'mysql-client-core-5.5': ensure => present
}

With that solution, I am getting the following error:

Error: Execution of '/usr/bin/yum -d 0 -e 0 -y list mysql-client-core-5.5' 
returned 1: Error: No matching Packages to list

Solution #2 found on Internet Forums

Found here.

It is actually proposing two solutions:

package { 'mysql-server' : ensure => '5.5' , }

and

package { 'mysql55w' : ensure => 'present' , }

In both cases I am getting a similar error, which is no other than package not found on the current installed repos

In order to fix all the problems above, I successfully added the necessary changes on the puppet manifest to install the repo where MySQL 5.5.40 lives.

After repuppetting again, I am now getting a different error:

Error: mysql55w-libs conflicts with mysql-libs-5.1.73-3.el6_5.i686

Of course, the old libraries are conflicting with the new ones. Fortunately, there is a workaround for this, as described here. I successfully added those commands to my puppet manifest (using the EXEC command)

yum install mysql.`uname -i` yum-plugin-replace
yum replace mysql --replace-with mysql55w

After all these workarounds, my puppet manifest executes fine, but only after chaining each declaration to execute it sequentially (puppet doesn't assume order). Otherwise, it may try to install Mysql 5.5 before to install the repo or before to change the libraries.

The Question

Well, the question is, is there any other way to manage this more gracefully in puppet?

It wasn't enough to tell puppet that I wanted MySQL installed. I actually had to tell Puppet how to do it.

My Puppet manifest looks like the good old fashion scripts that Puppet is supposed to replace. I can't concentrate in what I want. I had to instruct it how to achieve it too

Upvotes: 1

Views: 1144

Answers (1)

Peter Souter
Peter Souter

Reputation: 5200

Even with configuration management package-providers can be a headache! :)

However, in this instance we can leverage the work by using a pre-existing module to manage Yum: example42/yum

Install the module like so:

puppet module install example42/yum

With this, it becomes much easier to manage, and you can install MySQL 5.5 much cleaner and idempotently:

  class { 'yum':
    defaultrepo => false,
    extrarepo   => '' ,
  }

  class { 'yum::repo::mysql_community':
    enabled_version => '5.5',
  }

  package { 'mysql-community-server':
    ensure  => '5.5.42-2.el6',
    require => Class['yum::repo::mysql_community'],
  }

As you can see, the only ordering used is the require on the package, to make sure the Yum repo has been setup before trying to install it.

Worked for me on a brand new Centos 6.6 Vagrant box:

# Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "puppetlabs/centos-6.6-64-puppet"

  config.vm.provision "shell", inline: "puppet module install example42/yum"

  config.vm.provision "puppet" do |puppet|
    puppet.manifests_path = "./"
    puppet.manifest_file  = "default.pp"
  end

end

Output:

==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Notice: Preparing to install into /etc/puppet/modules ...
==> default: Notice: Downloading from https://forgeapi.puppetlabs.com ...
==> default: Notice: Installing -- do not interrupt ...
==> default: /etc/puppet/modules
==> default: └─┬ example42-yum (v2.1.17)
==> default:   └── example42-puppi (v2.1.10)
==> default: Running provisioner: puppet...
==> default: Running Puppet with default.pp...
==> default: Notice: Compiled catalog for localhost.home in environment production in 0.85 seconds
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql-connectors-community]/File[/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql]/ensure: defined content as '{md5}26b9ed77a3a087874a27103c1f9d6a6f'
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql-tools-community]/File[/etc/yum.repos.d/mysql-tools-community.repo]/ensure: created
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql56-community]/File[/etc/yum.repos.d/mysql56-community.repo]/ensure: created
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql56-community]/Yumrepo[mysql56-community]/ensure: created
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql57-community-dmr]/File[/etc/yum.repos.d/mysql57-community-dmr.repo]/ensure: created
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql57-community-dmr]/Yumrepo[mysql57-community-dmr]/ensure: created
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql-connectors-community]/File[/etc/yum.repos.d/mysql-connectors-community.repo]/ensure: created
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql-connectors-community]/Yumrepo[mysql-connectors-community]/ensure: created
==> default: Notice: /Stage[main]/Yum::Prerequisites/Yum::Plugin[priorities]/Package[yum-plugin-priorities]/ensure: created
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql-tools-community]/Yumrepo[mysql-tools-community]/ensure: created
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql55-community]/File[/etc/yum.repos.d/mysql55-community.repo]/ensure: created
==> default: Notice: /Stage[main]/Yum::Repo::Mysql_community/Yum::Managed_yumrepo[mysql55-community]/Yumrepo[mysql55-community]/ensure: created
==> default: Notice: /Stage[main]/Main/Node[default]/Package[mysql-community-server]/ensure: created
==> default: Notice: Finished catalog run in 63.97 seconds

Upvotes: 2

Related Questions