I am currently updating the MySQL cookbook community so that it can be used to install Percona, which is a shorthand replacement for the MySQL warehouse, but has some additional features that make HA and clustering easy to enable.
All my additions worked well until I wanted to use the ruby ββrecipe in the cookbook. To install "rubygem" mysql, the "chef_gem" provider is used. Since this is a native extension, it must be compiled, and for this you need to install development files for MySQL.
If I use regular MySQL binaries, everything works well, since MySQL is already in Centos repositories. However, in order for me to install Percona packages, I need to make sure that the repo is in '/etc/yum.repos.d'. The problem I am facing is that I cannot get the chef to do this work before trying to install the mysql gem.
So what happens, the system tries to compile gem mysql without the development header files for MySQL (Percona), and even if they are correctly specified, they were not found because the repository was not configured.
I created a percona-repo recipe that works using the yum provider, but it does not start before chef_gem does. I know that the chef has two phases to run, and I assume that chef_gem collects all the gems at the compilation stage, regardless of where they are in the general launch list, and then sets all the items requested at the beginning. Then the repository recipe will be launched.
I tried playing around with a Ruby recipe to do something like:
include_recipe "mysql::percona_repo" node['mysql']['client']['packages'].each do |mysql_pack| package mysql_pack do action :nothing end.run_action(:install) end chef_gem "mysql" do action :nothing end.run_action(:install)
But that does not work. Chef_gem always starts before my precona_repo recipe, so the package installs a failure, which, if it is so far away, will mean that installing the ruby ββgem will also fail.
If anyone has any bright ideas on how I can solve this, please let me know.
Update
Thanks to Mark's suggestion, now I am updating the ruby ββrecipe so that I call resources to add a new key and repo to the server:
resources(:yum_key => "RPM-GPG-KEY-percona").run_action(:add) resources(:yum_repository => "Percona").run_action(:add)
And now I see how they are activated in chef mode. However, when I look at the file system, there are no files there, so the installation of mysql client packages fails.
In the yum cookbook, I have something useful and found that the yum_key provider is trying to run "remote_file" to load the key, as you expected. However, this "remote_file" is not running. Therefore, I tried to run this as a resource, as indicated above, but it has a variable in the name, so I cannot name it effectively, for example:
remote_file "/etc/pki/rpm-gpg/#{new_resource.key}" do ... end
I think I'm starting to go down a bit with rabbit warren. I will continue to try to make the business work, but most are welcome. I try not to follow the path of direct coding in the repo in this recipe, as I prefer to use what I know works.