背景
我正在使用Centos 6.5和Puppet 3.7.3。
我已经安装了模块puppetlabs-mysql v3.1.0
Centos 6.5默认安装MySql 5.1.73。我想要实现的是使用上述模块将该版本通过Puppet升级到5.5.40
初始解决方案
好吧,我找不到合适的解决方案来做到这一点。官方文档仅介绍如何配置puppet清单以安装MySql ,而不考虑版本。这不适合我,因为在运行木偶代理后版本保持不变。
package { "MySQL-client": ensure => installed }
在互联网论坛上找到解决方案#1
找到here。
package {
'mysql-client-core-5.5': ensure => present
}
使用该解决方案,我收到以下错误:
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
在互联网论坛上找到解决方案#2
找到here。
实际上它提出了两个解决方案:
package { 'mysql-server' : ensure => '5.5' , }
和
package { 'mysql55w' : ensure => 'present' , }
在这两种情况下,我都会遇到类似的错误,这只是当前已安装的回购
为了解决上述所有问题,我成功地在puppet清单上添加了必要的更改,以安装MySQL 5.5.40所在的repo。
再次重新编制后,我现在遇到了另一个错误:
Error: mysql55w-libs conflicts with mysql-libs-5.1.73-3.el6_5.i686
当然,旧图书馆与新图书馆相冲突。幸运的是,正如here所述,有一种解决方法。我成功地将这些命令添加到我的puppet清单(使用EXEC命令)
yum install mysql.`uname -i` yum-plugin-replace
yum replace mysql --replace-with mysql55w
在所有这些变通办法之后,我的木偶清单执行得很好,但只有在链接每个声明后才能顺序执行它(木偶不承担顺序)。否则,它可能会尝试安装Mysql 5.5之前安装repo或更改库之前。
问题
嗯,问题是,有没有其他方法可以在木偶中更优雅地管理它?
告诉木偶我想安装MySQL是不够的。我实际上不得不告诉Puppet如何做到这一点。
我的Puppet清单看起来像是Puppet应该替换的旧时尚脚本。我不能专注于我想要的东西。我必须指示它如何实现它
答案 0 :(得分:2)
即使使用配置管理包,提供商也很头疼! :)
但是,在这种情况下,我们可以通过使用预先存在的模块来管理Yum来利用这项工作:example42/yum
安装模块如下:
puppet module install example42/yum
有了它,它变得更容易管理,你可以安装MySQL 5.5更清洁和明确:
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'],
}
正如您所看到的,唯一使用的顺序是包上的require
,以确保在尝试安装Yum repo之前已经设置了它。
在全新的Centos 6.6 Vagrant盒子上为我工作:
# 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
输出:
==> 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