puppetlabs-mysql-3.10.0/0000755005276200011600000000000013010160602014772 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/CONTRIBUTING.md0000644005276200011600000001741712763636535017270 0ustar jenkinsjenkinsChecklist (and a short version for the impatient) ================================================= * Commits: - Make commits of logical units. - Check for unnecessary whitespace with "git diff --check" before committing. - Commit using Unix line endings (check the settings around "crlf" in git-config(1)). - Do not check in commented out code or unneeded files. - The first line of the commit message should be a short description (50 characters is the soft limit, excluding ticket number(s)), and should skip the full stop. - Associate the issue in the message. The first line should include the issue number in the form "(#XXXX) Rest of message". - The body should provide a meaningful commit message, which: - uses the imperative, present tense: "change", not "changed" or "changes". - includes motivation for the change, and contrasts its implementation with the previous behavior. - Make sure that you have tests for the bug you are fixing, or feature you are adding. - Make sure the test suites passes after your commit: `bundle exec rspec spec/acceptance` More information on [testing](#Testing) below - When introducing a new feature, make sure it is properly documented in the README.md * Submission: * Pre-requisites: - Make sure you have a [GitHub account](https://github.com/join) - [Create a ticket](https://tickets.puppetlabs.com/secure/CreateIssue!default.jspa), or [watch the ticket](https://tickets.puppetlabs.com/browse/) you are patching for. * Preferred method: - Fork the repository on GitHub. - Push your changes to a topic branch in your fork of the repository. (the format ticket/1234-short_description_of_change is usually preferred for this project). - Submit a pull request to the repository in the puppetlabs organization. The long version ================ 1. Make separate commits for logically separate changes. Please break your commits down into logically consistent units which include new or changed tests relevant to the rest of the change. The goal of doing this is to make the diff easier to read for whoever is reviewing your code. In general, the easier your diff is to read, the more likely someone will be happy to review it and get it into the code base. If you are going to refactor a piece of code, please do so as a separate commit from your feature or bug fix changes. We also really appreciate changes that include tests to make sure the bug is not re-introduced, and that the feature is not accidentally broken. Describe the technical detail of the change(s). If your description starts to get too long, that is a good sign that you probably need to split up your commit into more finely grained pieces. Commits which plainly describe the things which help reviewers check the patch and future developers understand the code are much more likely to be merged in with a minimum of bike-shedding or requested changes. Ideally, the commit message would include information, and be in a form suitable for inclusion in the release notes for the version of Puppet that includes them. Please also check that you are not introducing any trailing whitespace or other "whitespace errors". You can do this by running "git diff --check" on your changes before you commit. 2. Sending your patches To submit your changes via a GitHub pull request, we _highly_ recommend that you have them on a topic branch, instead of directly on "master". It makes things much easier to keep track of, especially if you decide to work on another thing before your first change is merged in. GitHub has some pretty good [general documentation](http://help.github.com/) on using their site. They also have documentation on [creating pull requests](http://help.github.com/send-pull-requests/). In general, after pushing your topic branch up to your repository on GitHub, you can switch to the branch in the GitHub UI and click "Pull Request" towards the top of the page in order to open a pull request. 3. Update the related GitHub issue. If there is a GitHub issue associated with the change you submitted, then you should update the ticket to include the location of your branch, along with any other commentary you may wish to make. Testing ======= Getting Started --------------- Our puppet modules provide [`Gemfile`](./Gemfile)s which can tell a ruby package manager such as [bundler](http://bundler.io/) what Ruby packages, or Gems, are required to build, develop, and test this software. Please make sure you have [bundler installed](http://bundler.io/#getting-started) on your system, then use it to install all dependencies needed for this project, by running ```shell % bundle install Fetching gem metadata from https://rubygems.org/........ Fetching gem metadata from https://rubygems.org/.. Using rake (10.1.0) Using builder (3.2.2) -- 8><-- many more --><8 -- Using rspec-system-puppet (2.2.0) Using serverspec (0.6.3) Using rspec-system-serverspec (1.0.0) Using bundler (1.3.5) Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. ``` NOTE some systems may require you to run this command with sudo. If you already have those gems installed, make sure they are up-to-date: ```shell % bundle update ``` With all dependencies in place and up-to-date we can now run the tests: ```shell % bundle exec rake spec ``` This will execute all the [rspec tests](http://rspec-puppet.com/) tests under [spec/defines](./spec/defines), [spec/classes](./spec/classes), and so on. rspec tests may have the same kind of dependencies as the module they are testing. While the module defines in its [Modulefile](./Modulefile), rspec tests define them in [.fixtures.yml](./fixtures.yml). Some puppet modules also come with [beaker](https://github.com/puppetlabs/beaker) tests. These tests spin up a virtual machine under [VirtualBox](https://www.virtualbox.org/)) with, controlling it with [Vagrant](http://www.vagrantup.com/) to actually simulate scripted test scenarios. In order to run these, you will need both of those tools installed on your system. You can run them by issuing the following command ```shell % bundle exec rake spec_clean % bundle exec rspec spec/acceptance ``` This will now download a pre-fabricated image configured in the [default node-set](./spec/acceptance/nodesets/default.yml), install puppet, copy this module and install its dependencies per [spec/spec_helper_acceptance.rb](./spec/spec_helper_acceptance.rb) and then run all the tests under [spec/acceptance](./spec/acceptance). Writing Tests ------------- XXX getting started writing tests. If you have commit access to the repository =========================================== Even if you have commit access to the repository, you will still need to go through the process above, and have someone else review and merge in your changes. The rule is that all changes must be reviewed by a developer on the project (that did not write the code) to ensure that all changes go through a code review process. Having someone other than the author of the topic branch recorded as performing the merge is the record that they performed the code review. Additional Resources ==================== * [Getting additional help](http://puppet.com/community/get-help) * [Writing tests](https://docs.puppet.com/guides/module_guides/bgtm.html#step-three-module-testing) * [General GitHub documentation](http://help.github.com/) * [GitHub pull request documentation](http://help.github.com/send-pull-requests/) puppetlabs-mysql-3.10.0/lib/0000755005276200011600000000000013010160602015540 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/facter/0000755005276200011600000000000013010160602017004 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/facter/mysql_server_id.rb0000644005276200011600000000031512763636535022572 0ustar jenkinsjenkinsdef get_mysql_id Facter.value(:macaddress).split(':')[2..-1].inject(0) { |total,value| (total << 6) + value.hex } end Facter.add("mysql_server_id") do setcode do get_mysql_id rescue nil end end puppetlabs-mysql-3.10.0/lib/facter/mysql_version.rb0000644005276200011600000000027212746170223022263 0ustar jenkinsjenkinsFacter.add("mysql_version") do setcode do mysql_ver = Facter::Util::Resolution.exec('mysql --version') if mysql_ver mysql_ver.match(/\d+\.\d+\.\d+/)[0] end end end puppetlabs-mysql-3.10.0/lib/facter/mysqld_version.rb0000644005276200011600000000016213010160217022410 0ustar jenkinsjenkinsFacter.add("mysqld_version") do setcode do Facter::Util::Resolution.exec('mysqld -V 2>/dev/null') end end puppetlabs-mysql-3.10.0/lib/puppet/0000755005276200011600000000000013010160602017055 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/puppet/type/0000755005276200011600000000000013010160602020036 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/puppet/type/mysql_datadir.rb0000644005276200011600000000150512746170223023240 0ustar jenkinsjenkinsPuppet::Type.newtype(:mysql_datadir) do @doc = 'Manage MySQL datadirs with mysql_install_db OR mysqld (5.7.6 and above).' ensurable autorequire(:package) { 'mysql-server' } newparam(:datadir, :namevar => true) do desc "The datadir name" end newparam(:basedir) do desc 'The basedir name, default /usr.' newvalues(/^\//) end newparam(:user) do desc 'The user for the directory default mysql (name, not uid).' end newparam(:defaults_extra_file) do desc "MySQL defaults-extra-file with absolute path (*.cnf)." newvalues(/^\/.*\.cnf$/) end newparam(:insecure, :boolean => true) do desc "Insecure initialization (needed for 5.7.6++)." end newparam(:log_error) do desc "The path to the mysqld error log file (used with the --log-error option)" newvalues(/^\//) end end puppetlabs-mysql-3.10.0/lib/puppet/type/mysql_database.rb0000644005276200011600000000103612746170223023373 0ustar jenkinsjenkinsPuppet::Type.newtype(:mysql_database) do @doc = 'Manage MySQL databases.' ensurable autorequire(:file) { '/root/.my.cnf' } autorequire(:class) { 'mysql::server' } newparam(:name, :namevar => true) do desc 'The name of the MySQL database to manage.' end newproperty(:charset) do desc 'The CHARACTER SET setting for the database' defaultto :utf8 newvalue(/^\S+$/) end newproperty(:collate) do desc 'The COLLATE setting for the database' defaultto :utf8_general_ci newvalue(/^\S+$/) end end puppetlabs-mysql-3.10.0/lib/puppet/type/mysql_user.rb0000644005276200011600000000730513010160217022575 0ustar jenkinsjenkins# This has to be a separate type to enable collecting Puppet::Type.newtype(:mysql_user) do @doc = 'Manage a MySQL user. This includes management of users password as well as privileges.' ensurable autorequire(:file) { '/root/.my.cnf' } autorequire(:class) { 'mysql::server' } newparam(:name, :namevar => true) do desc "The name of the user. This uses the 'username@hostname' or username@hostname." validate do |value| # http://dev.mysql.com/doc/refman/5.5/en/identifiers.html # If at least one special char is used, string must be quoted # http://stackoverflow.com/questions/8055727/negating-a-backreference-in-regular-expressions/8057827#8057827 if matches = /^(['`"])((?:(?!\1).)*)\1@([\w%\.:\-\/]+)$/.match(value) user_part = matches[2] host_part = matches[3] elsif matches = /^([0-9a-zA-Z$_]*)@([\w%\.:\-\/]+)$/.match(value) user_part = matches[1] host_part = matches[2] elsif matches = /^((?!['`"]).*[^0-9a-zA-Z$_].*)@(.+)$/.match(value) user_part = matches[1] host_part = matches[2] else raise(ArgumentError, "Invalid database user #{value}") end mysql_version = Facter.value(:mysql_version) unless mysql_version.nil? if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8') < 0 and user_part.size > 16 raise(ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters') elsif Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') < 0 and user_part.size > 32 raise(ArgumentError, 'MySQL usernames are limited to a maximum of 32 characters') elsif Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') > 0 and user_part.size > 80 raise(ArgumentError, 'MySQL usernames are limited to a maximum of 80 characters') end end end munge do |value| matches = /^((['`"]?).*\2)@(.+)$/.match(value) "#{matches[1]}@#{matches[3].downcase}" end end newproperty(:password_hash) do desc 'The password hash of the user. Use mysql_password() for creating such a hash.' newvalue(/\w*/) end newproperty(:plugin) do desc 'The authentication plugin of the user.' newvalue(/\w+/) end newproperty(:max_user_connections) do desc "Max concurrent connections for the user. 0 means no (or global) limit." newvalue(/\d+/) end newproperty(:max_connections_per_hour) do desc "Max connections per hour for the user. 0 means no (or global) limit." newvalue(/\d+/) end newproperty(:max_queries_per_hour) do desc "Max queries per hour for the user. 0 means no (or global) limit." newvalue(/\d+/) end newproperty(:max_updates_per_hour) do desc "Max updates per hour for the user. 0 means no (or global) limit." newvalue(/\d+/) end newproperty(:tls_options, :array_matching => :all) do desc "Options to that set the TLS-related REQUIRE attributes for the user." validate do |value| value = [value] if not value.is_a?(Array) if value.include? 'NONE' or value.include? 'SSL' or value.include? 'X509' if value.length > 1 raise(ArgumentError, "REQUIRE tls options NONE, SSL and X509 cannot be used with other options, you may only use one of them.") end else value.each do |opt| if not o = opt.match(/^(CIPHER|ISSUER|SUBJECT)/i) raise(ArgumentError, "Invalid tls option #{o}") end end end end def insync?(is) # The current value may be nil and we don't # want to call sort on it so make sure we have arrays if is.is_a?(Array) and @should.is_a?(Array) is.sort == @should.sort else is == @should end end end end puppetlabs-mysql-3.10.0/lib/puppet/type/mysql_grant.rb0000644005276200011600000000736312763636535022767 0ustar jenkinsjenkins# This has to be a separate type to enable collecting Puppet::Type.newtype(:mysql_grant) do @doc = "Manage a MySQL user's rights." ensurable autorequire(:file) { '/root/.my.cnf' } autorequire(:mysql_user) { self[:user] } def initialize(*args) super # Forcibly munge any privilege with 'ALL' in the array to exist of just # 'ALL'. This can't be done in the munge in the property as that iterates # over the array and there's no way to replace the entire array before it's # returned to the provider. if self[:ensure] == :present and Array(self[:privileges]).count > 1 and self[:privileges].to_s.include?('ALL') self[:privileges] = 'ALL' end # Sort the privileges array in order to ensure the comparision in the provider # self.instances method match. Otherwise this causes it to keep resetting the # privileges. self[:privileges] = Array(self[:privileges]).map{ |priv| # split and sort the column_privileges in the parentheses and rejoin if priv.include?('(') type, col=priv.strip.split(/\s+|\b/,2) type.upcase + " (" + col.slice(1...-1).strip.split(/\s*,\s*/).sort.join(', ') + ")" else priv.strip.upcase end }.uniq.reject{|k| k == 'GRANT' or k == 'GRANT OPTION'}.sort! end validate do fail('privileges parameter is required.') if self[:ensure] == :present and self[:privileges].nil? fail('table parameter is required.') if self[:ensure] == :present and self[:table].nil? fail('user parameter is required.') if self[:ensure] == :present and self[:user].nil? fail('name must match user and table parameters') if self[:name] != "#{self[:user]}/#{self[:table]}" end newparam(:name, :namevar => true) do desc 'Name to describe the grant.' munge do |value| value.delete("'") end end newproperty(:privileges, :array_matching => :all) do desc 'Privileges for user' end newproperty(:table) do desc 'Table to apply privileges to.' munge do |value| value.delete("`") end newvalues(/.*\..*/,/@/) end newproperty(:user) do desc 'User to operate on.' validate do |value| # http://dev.mysql.com/doc/refman/5.5/en/identifiers.html # If at least one special char is used, string must be quoted # http://stackoverflow.com/questions/8055727/negating-a-backreference-in-regular-expressions/8057827#8057827 if matches = /^(['`"])((?!\1).)*\1@([\w%\.:\-\/]+)$/.match(value) user_part = matches[2] host_part = matches[3] elsif matches = /^([0-9a-zA-Z$_]*)@([\w%\.:\-\/]+)$/.match(value) user_part = matches[1] host_part = matches[2] elsif matches = /^((?!['`"]).*[^0-9a-zA-Z$_].*)@(.+)$/.match(value) user_part = matches[1] host_part = matches[2] else raise(ArgumentError, "Invalid database user #{value}") end mysql_version = Facter.value(:mysql_version) unless mysql_version.nil? if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8') < 0 and user_part.size > 16 raise(ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters') elsif Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') < 0 and user_part.size > 32 raise(ArgumentError, 'MySQL usernames are limited to a maximum of 32 characters') elsif Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') > 0 and user_part.size > 80 raise(ArgumentError, 'MySQL usernames are limited to a maximum of 80 characters') end end end munge do |value| matches = /^((['`"]?).*\2)@(.+)$/.match(value) "#{matches[1]}@#{matches[3].downcase}" end end newproperty(:options, :array_matching => :all) do desc 'Options to grant.' end end puppetlabs-mysql-3.10.0/lib/puppet/type/mysql_plugin.rb0000644005276200011600000000050412746170223023124 0ustar jenkinsjenkinsPuppet::Type.newtype(:mysql_plugin) do @doc = 'Manage MySQL plugins.' ensurable autorequire(:file) { '/root/.my.cnf' } newparam(:name, :namevar => true) do desc 'The name of the MySQL plugin to manage.' end newproperty(:soname) do desc 'The name of the library' newvalue(/^\w+\.\w+$/) end end puppetlabs-mysql-3.10.0/lib/puppet/parser/0000755005276200011600000000000013010160602020351 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/puppet/parser/functions/0000755005276200011600000000000013010160602022361 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/puppet/parser/functions/mysql_strip_hash.rb0000644005276200011600000000104312746170216026316 0ustar jenkinsjenkinsmodule Puppet::Parser::Functions newfunction(:mysql_strip_hash, :type => :rvalue, :arity => 1, :doc => <<-EOS TEMPORARY FUNCTION: EXPIRES 2014-03-10 When given a hash this function strips out all blank entries. EOS ) do |args| hash = args[0] unless hash.is_a?(Hash) raise(Puppet::ParseError, 'mysql_strip_hash(): Requires hash to work with') end # Filter out all the top level blanks. hash.reject{|k,v| v == ''}.each do |k,v| if v.is_a?(Hash) v.reject!{|ki,vi| vi == '' } end end end end puppetlabs-mysql-3.10.0/lib/puppet/parser/functions/mysql_password.rb0000644005276200011600000000106712746170223026020 0ustar jenkinsjenkins# hash a string as mysql's "PASSWORD()" function would do it require 'digest/sha1' module Puppet::Parser::Functions newfunction(:mysql_password, :type => :rvalue, :doc => <<-EOS Returns the mysql password hash from the clear text password. EOS ) do |args| raise(Puppet::ParseError, 'mysql_password(): Wrong number of arguments ' + "given (#{args.size} for 1)") if args.size != 1 return '' if args[0].empty? return args[0] if args[0] =~ /\*[A-F0-9]{40}$/ '*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(args[0])).upcase end end puppetlabs-mysql-3.10.0/lib/puppet/parser/functions/mysql_deepmerge.rb0000644005276200011600000000416312746170216026115 0ustar jenkinsjenkinsmodule Puppet::Parser::Functions newfunction(:mysql_deepmerge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| Recursively merges two or more hashes together and returns the resulting hash. For example: $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } } $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } } $merged_hash = mysql_deepmerge($hash1, $hash2) # The resulting hash is equivalent to: # $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } When there is a duplicate key that is a hash, they are recursively merged. When there is a duplicate key that is not a hash, the key in the rightmost hash will "win." When there are conficting uses of dashes and underscores in two keys (which mysql would otherwise equate), the rightmost style will win. ENDHEREDOC if args.length < 2 raise Puppet::ParseError, ("mysql_deepmerge(): wrong number of arguments (#{args.length}; must be at least 2)") end result = Hash.new args.each do |arg| next if arg.is_a? String and arg.empty? # empty string is synonym for puppet's undef # If the argument was not a hash, skip it. unless arg.is_a?(Hash) raise Puppet::ParseError, "mysql_deepmerge: unexpected argument type #{arg.class}, only expects hash arguments" end # Now we have to traverse our hash assigning our non-hash values # to the matching keys in our result while following our hash values # and repeating the process. overlay( result, arg ) end return( result ) end end def has_normalized!(hash, key) return true if hash.has_key?( key ) return false unless key.match(/-|_/) other_key = key.include?('-') ? key.gsub( '-', '_' ) : key.gsub( '_', '-' ) return false unless hash.has_key?( other_key ) hash[key] = hash.delete( other_key ) return true; end def overlay( hash1, hash2 ) hash2.each do |key, value| if(has_normalized!( hash1, key ) and value.is_a?(Hash) and hash1[key].is_a?(Hash)) overlay( hash1[key], value ) else hash1[key] = value end end end puppetlabs-mysql-3.10.0/lib/puppet/parser/functions/mysql_dirname.rb0000644005276200011600000000061012746170223025566 0ustar jenkinsjenkinsmodule Puppet::Parser::Functions newfunction(:mysql_dirname, :type => :rvalue, :doc => <<-EOS Returns the dirname of a path. EOS ) do |arguments| raise(Puppet::ParseError, "mysql_dirname(): Wrong number of arguments " + "given (#{arguments.size} for 1)") if arguments.size < 1 path = arguments[0] return File.dirname(path) end end # vim: set ts=2 sw=2 et : puppetlabs-mysql-3.10.0/lib/puppet/provider/0000755005276200011600000000000013010160602020707 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/puppet/provider/mysql_database/0000755005276200011600000000000013010160602023700 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/puppet/provider/mysql_database/mysql.rb0000644005276200011600000000427012746170223025414 0ustar jenkinsjenkinsrequire File.expand_path(File.join(File.dirname(__FILE__), '..', 'mysql')) Puppet::Type.type(:mysql_database).provide(:mysql, :parent => Puppet::Provider::Mysql) do desc 'Manages MySQL databases.' commands :mysql => 'mysql' def self.instances mysql([defaults_file, '-NBe', 'show databases'].compact).split("\n").collect do |name| attributes = {} mysql([defaults_file, '-NBe', "show variables like '%_database'", name].compact).split("\n").each do |line| k,v = line.split(/\s/) attributes[k] = v end new(:name => name, :ensure => :present, :charset => attributes['character_set_database'], :collate => attributes['collation_database'] ) end end # We iterate over each mysql_database entry in the catalog and compare it against # the contents of the property_hash generated by self.instances def self.prefetch(resources) databases = instances resources.keys.each do |database| if provider = databases.find { |db| db.name == database } resources[database].provider = provider end end end def create mysql([defaults_file, '-NBe', "create database if not exists `#{@resource[:name]}` character set `#{@resource[:charset]}` collate `#{@resource[:collate]}`"].compact) @property_hash[:ensure] = :present @property_hash[:charset] = @resource[:charset] @property_hash[:collate] = @resource[:collate] exists? ? (return true) : (return false) end def destroy mysql([defaults_file, '-NBe', "drop database if exists `#{@resource[:name]}`"].compact) @property_hash.clear exists? ? (return false) : (return true) end def exists? @property_hash[:ensure] == :present || false end mk_resource_methods def charset=(value) mysql([defaults_file, '-NBe', "alter database `#{resource[:name]}` CHARACTER SET #{value}"].compact) @property_hash[:charset] = value charset == value ? (return true) : (return false) end def collate=(value) mysql([defaults_file, '-NBe', "alter database `#{resource[:name]}` COLLATE #{value}"].compact) @property_hash[:collate] = value collate == value ? (return true) : (return false) end end puppetlabs-mysql-3.10.0/lib/puppet/provider/mysql_plugin/0000755005276200011600000000000013010160602023432 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/puppet/provider/mysql_plugin/mysql.rb0000644005276200011600000000314312746170223025144 0ustar jenkinsjenkinsrequire File.expand_path(File.join(File.dirname(__FILE__), '..', 'mysql')) Puppet::Type.type(:mysql_plugin).provide(:mysql, :parent => Puppet::Provider::Mysql) do desc 'Manages MySQL plugins.' commands :mysql => 'mysql' def self.instances mysql([defaults_file, '-NBe', 'show plugins'].compact).split("\n").collect do |line| name, status, type, library, license = line.split(/\t/) new(:name => name, :ensure => :present, :soname => library ) end end # We iterate over each mysql_plugin entry in the catalog and compare it against # the contents of the property_hash generated by self.instances def self.prefetch(resources) plugins = instances resources.keys.each do |plugin| if provider = plugins.find { |pl| pl.name == plugin } resources[plugin].provider = provider end end end def create # Use plugin_name.so as soname if it's not specified. This won't work on windows as # there it should be plugin_name.dll @resource[:soname].nil? ? (soname=@resource[:name] + '.so') : (soname=@resource[:soname]) mysql([defaults_file, '-NBe', "install plugin #{@resource[:name]} soname '#{soname}'"].compact) @property_hash[:ensure] = :present @property_hash[:soname] = @resource[:soname] exists? ? (return true) : (return false) end def destroy mysql([defaults_file, '-NBe', "uninstall plugin #{@resource[:name]}"].compact) @property_hash.clear exists? ? (return false) : (return true) end def exists? @property_hash[:ensure] == :present || false end mk_resource_methods end puppetlabs-mysql-3.10.0/lib/puppet/provider/mysql_user/0000755005276200011600000000000013010160602023112 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/puppet/provider/mysql_user/mysql.rb0000644005276200011600000002215213010160217024610 0ustar jenkinsjenkinsrequire File.expand_path(File.join(File.dirname(__FILE__), '..', 'mysql')) Puppet::Type.type(:mysql_user).provide(:mysql, :parent => Puppet::Provider::Mysql) do desc 'manage users for a mysql database.' commands :mysql => 'mysql' # Build a property_hash containing all the discovered information about MySQL # users. def self.instances users = mysql([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"].compact).split("\n") # To reduce the number of calls to MySQL we collect all the properties in # one big swoop. users.collect do |name| if mysqld_version.nil? ## Default ... query = "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{name}'" else if (mysqld_type == "mysql" or mysqld_type == "percona") and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0 query = "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, AUTHENTICATION_STRING, PLUGIN FROM mysql.user WHERE CONCAT(user, '@', host) = '#{name}'" else query = "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{name}'" end end @max_user_connections, @max_connections_per_hour, @max_queries_per_hour, @max_updates_per_hour, ssl_type, ssl_cipher, x509_issuer, x509_subject, @password, @plugin = mysql([defaults_file, "-NBe", query].compact).split(/\s/) @tls_options = parse_tls_options(ssl_type, ssl_cipher, x509_issuer, x509_subject) new(:name => name, :ensure => :present, :password_hash => @password, :plugin => @plugin, :max_user_connections => @max_user_connections, :max_connections_per_hour => @max_connections_per_hour, :max_queries_per_hour => @max_queries_per_hour, :max_updates_per_hour => @max_updates_per_hour, :tls_options => @tls_options, ) end end # We iterate over each mysql_user entry in the catalog and compare it against # the contents of the property_hash generated by self.instances def self.prefetch(resources) users = instances resources.keys.each do |name| if provider = users.find { |user| user.name == name } resources[name].provider = provider end end end def create merged_name = @resource[:name].sub('@', "'@'") password_hash = @resource.value(:password_hash) plugin = @resource.value(:plugin) max_user_connections = @resource.value(:max_user_connections) || 0 max_connections_per_hour = @resource.value(:max_connections_per_hour) || 0 max_queries_per_hour = @resource.value(:max_queries_per_hour) || 0 max_updates_per_hour = @resource.value(:max_updates_per_hour) || 0 tls_options = @resource.value(:tls_options) || ['NONE'] # Use CREATE USER to be compatible with NO_AUTO_CREATE_USER sql_mode # This is also required if you want to specify a authentication plugin if !plugin.nil? if plugin == 'sha256_password' and !password_hash.nil? mysql([defaults_file, system_database, '-e', "CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}' AS '#{password_hash}'"].compact) else mysql([defaults_file, system_database, '-e', "CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}'"].compact) end @property_hash[:ensure] = :present @property_hash[:plugin] = plugin else mysql([defaults_file, system_database, '-e', "CREATE USER '#{merged_name}' IDENTIFIED BY PASSWORD '#{password_hash}'"].compact) @property_hash[:ensure] = :present @property_hash[:password_hash] = password_hash end mysql([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO '#{merged_name}' WITH MAX_USER_CONNECTIONS #{max_user_connections} MAX_CONNECTIONS_PER_HOUR #{max_connections_per_hour} MAX_QUERIES_PER_HOUR #{max_queries_per_hour} MAX_UPDATES_PER_HOUR #{max_updates_per_hour}"].compact) @property_hash[:max_user_connections] = max_user_connections @property_hash[:max_connections_per_hour] = max_connections_per_hour @property_hash[:max_queries_per_hour] = max_queries_per_hour @property_hash[:max_updates_per_hour] = max_updates_per_hour merged_tls_options = tls_options.join(' AND ') if (((mysqld_type == "mysql" or mysqld_type == "percona") and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0) or (mysqld_type == 'mariadb' and Puppet::Util::Package.versioncmp(mysqld_version, '10.2.0') >= 0)) mysql([defaults_file, system_database, '-e', "ALTER USER '#{merged_name}' REQUIRE #{merged_tls_options}"].compact) else mysql([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO '#{merged_name}' REQUIRE #{merged_tls_options}"].compact) end @property_hash[:tls_options] = tls_options exists? ? (return true) : (return false) end def destroy merged_name = @resource[:name].sub('@', "'@'") mysql([defaults_file, system_database, '-e', "DROP USER '#{merged_name}'"].compact) @property_hash.clear exists? ? (return false) : (return true) end def exists? @property_hash[:ensure] == :present || false end ## ## MySQL user properties ## # Generates method for all properties of the property_hash mk_resource_methods def password_hash=(string) merged_name = self.class.cmd_user(@resource[:name]) # We have a fact for the mysql version ... if mysqld_version.nil? # default ... if mysqld_version does not work mysql([defaults_file, system_database, '-e', "SET PASSWORD FOR #{merged_name} = '#{string}'"].compact) else # Version >= 5.7.6 (many password related changes) if (mysqld_type == "mysql" or mysqld_type == "percona") and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0 if string.match(/^\*/) mysql([defaults_file, system_database, '-e', "ALTER USER #{merged_name} IDENTIFIED WITH mysql_native_password AS '#{string}'"].compact) else raise ArgumentError, "Only mysql_native_password (*ABCD...XXX) hashes are supported" end else # older versions mysql([defaults_file, system_database, '-e', "SET PASSWORD FOR #{merged_name} = '#{string}'"].compact) end end password_hash == string ? (return true) : (return false) end def max_user_connections=(int) merged_name = self.class.cmd_user(@resource[:name]) mysql([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO #{merged_name} WITH MAX_USER_CONNECTIONS #{int}"].compact).chomp max_user_connections == int ? (return true) : (return false) end def max_connections_per_hour=(int) merged_name = self.class.cmd_user(@resource[:name]) mysql([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO #{merged_name} WITH MAX_CONNECTIONS_PER_HOUR #{int}"].compact).chomp max_connections_per_hour == int ? (return true) : (return false) end def max_queries_per_hour=(int) merged_name = self.class.cmd_user(@resource[:name]) mysql([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO #{merged_name} WITH MAX_QUERIES_PER_HOUR #{int}"].compact).chomp max_queries_per_hour == int ? (return true) : (return false) end def max_updates_per_hour=(int) merged_name = self.class.cmd_user(@resource[:name]) mysql([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO #{merged_name} WITH MAX_UPDATES_PER_HOUR #{int}"].compact).chomp max_updates_per_hour == int ? (return true) : (return false) end def tls_options=(array) merged_name = self.class.cmd_user(@resource[:name]) merged_tls_options = array.join(' AND ') if (((mysqld_type == "mysql" or mysqld_type == "percona") and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0) or (mysqld_type == 'mariadb' and Puppet::Util::Package.versioncmp(mysqld_version, '10.2.0') >= 0)) mysql([defaults_file, system_database, '-e', "ALTER USER #{merged_name} REQUIRE #{merged_tls_options}"].compact) else mysql([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO #{merged_name} REQUIRE #{merged_tls_options}"].compact) end tls_options == array ? (return true) : (return false) end def self.parse_tls_options(ssl_type, ssl_cipher, x509_issuer, x509_subject) if ssl_type == 'ANY' return ['SSL'] elsif ssl_type == 'X509' return ['X509'] elsif ssl_type == 'SPECIFIED' options = [] options << "CIPHER #{ssl_cipher}" if not ssl_cipher.nil? and not ssl_cipher.empty? options << "ISSUER #{x509_issuer}" if not x509_issuer.nil? and not x509_issuer.empty? options << "SUBJECT #{x509_subject}" if not x509_subject.nil? and not x509_subject.empty? return options else return ['NONE'] end end end puppetlabs-mysql-3.10.0/lib/puppet/provider/mysql.rb0000644005276200011600000000621712763636535022442 0ustar jenkinsjenkinsclass Puppet::Provider::Mysql < Puppet::Provider # Without initvars commands won't work. initvars # Make sure we find mysql commands on CentOS and FreeBSD ENV['PATH']=ENV['PATH'] + ':/usr/libexec:/usr/local/libexec:/usr/local/bin' commands :mysql => 'mysql' commands :mysqld => 'mysqld' commands :mysqladmin => 'mysqladmin' # Optional defaults file def self.defaults_file if File.file?("#{Facter.value(:root_home)}/.my.cnf") "--defaults-extra-file=#{Facter.value(:root_home)}/.my.cnf" else nil end end def self.mysqld_type # find the mysql "dialect" like mariadb / mysql etc. mysqld_version_string.scan(/mariadb/i) { return "mariadb" } mysqld_version_string.scan(/\s\(percona/i) { return "percona" } return "mysql" end def mysqld_type self.class.mysqld_type end def self.mysqld_version_string # As the possibility of the mysqld being remote we need to allow the version string to be overridden, this can be done by facter.value as seen below. In the case that it has not been set and the facter value is nil we use the mysql -v command to ensure we report the correct version of mysql for later use cases. @mysqld_version_string ||= Facter.value(:mysqld_version) || mysqld('-V') end def mysqld_version_string self.class.mysqld_version_string end def self.mysqld_version # note: be prepared for '5.7.6-rc-log' etc results # versioncmp detects 5.7.6-log to be newer then 5.7.6 # this is why we need the trimming. mysqld_version_string.scan(/\d+\.\d+\.\d+/).first unless mysqld_version_string.nil? end def mysqld_version self.class.mysqld_version end def defaults_file self.class.defaults_file end def self.users mysql([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"].compact).split("\n") end # Optional parameter to run a statement on the MySQL system database. def self.system_database '--database=mysql' end def system_database self.class.system_database end # Take root@localhost and munge it to 'root'@'localhost' def self.cmd_user(user) "'#{user.sub('@', "'@'")}'" end # Take root.* and return ON `root`.* def self.cmd_table(table) table_string = '' # We can't escape *.* so special case this. if table == '*.*' table_string << '*.*' # Special case also for PROCEDURES elsif table.start_with?('PROCEDURE ') table_string << table.sub(/^PROCEDURE (.*)(\..*)/, 'PROCEDURE `\1`\2') else table_string << table.sub(/^(.*)(\..*)/, '`\1`\2') end table_string end def self.cmd_privs(privileges) if privileges.include?('ALL') return 'ALL PRIVILEGES' else priv_string = '' privileges.each do |priv| priv_string << "#{priv}, " end end # Remove trailing , from the last element. priv_string.sub(/, $/, '') end # Take in potential options and build up a query string with them. def self.cmd_options(options) option_string = '' options.each do |opt| if opt == 'GRANT' option_string << ' WITH GRANT OPTION' end end option_string end end puppetlabs-mysql-3.10.0/lib/puppet/provider/mysql_datadir/0000755005276200011600000000000013010160602023544 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/puppet/provider/mysql_datadir/mysql.rb0000644005276200011600000000507113010160217025243 0ustar jenkinsjenkinsrequire File.expand_path(File.join(File.dirname(__FILE__), '..', 'mysql')) Puppet::Type.type(:mysql_datadir).provide(:mysql, :parent => Puppet::Provider::Mysql) do desc 'manage data directories for mysql instances' initvars # Make sure we find mysqld on CentOS and mysql_install_db on Gentoo ENV['PATH']=ENV['PATH'] + ':/usr/libexec:/usr/share/mysql/scripts:/opt/rh/mysql55/root/usr/bin:/opt/rh/mysql55/root/usr/libexec' commands :mysqld => 'mysqld' commands :mysql_install_db => 'mysql_install_db' def create name = @resource[:name] insecure = @resource.value(:insecure) || true defaults_extra_file = @resource.value(:defaults_extra_file) user = @resource.value(:user) || "mysql" basedir = @resource.value(:basedir) datadir = @resource.value(:datadir) || @resource[:name] log_error = @resource.value(:log_error) || "/var/tmp/mysqld_initialize.log" unless defaults_extra_file.nil? if File.exist?(defaults_extra_file) defaults_extra_file="--defaults-extra-file=#{defaults_extra_file}" else raise ArgumentError, "Defaults-extra-file #{defaults_extra_file} is missing" end end if insecure == true initialize="--initialize-insecure" else initialize="--initialize" end opts = [ defaults_extra_file ] %w(basedir datadir user).each do |opt| val = eval(opt) opts<<"--#{opt}=#{val}" unless val.nil? end if mysqld_version.nil? debug("Installing MySQL data directory with mysql_install_db #{opts.compact.join(" ")}") mysql_install_db(opts.compact) else if (mysqld_type == "mysql" or mysqld_type == "percona") and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0 opts<<"--log-error=#{log_error}" opts<<"#{initialize}" debug("Initializing MySQL data directory >= 5.7.6 with mysqld: #{opts.compact.join(" ")}") mysqld(opts.compact) else debug("Installing MySQL data directory with mysql_install_db #{opts.compact.join(" ")}") mysql_install_db(opts.compact) end end exists? end def destroy name = @resource[:name] raise ArgumentError, "ERROR: Resource can not be removed" end def exists? datadir = @resource[:datadir] (File.directory?("#{datadir}/mysql")) && (Dir.entries("#{datadir}/mysql") - %w{ . .. }).any? end ## ## MySQL datadir properties ## # Generates method for all properties of the property_hash mk_resource_methods end puppetlabs-mysql-3.10.0/lib/puppet/provider/mysql_grant/0000755005276200011600000000000013010160602023247 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/lib/puppet/provider/mysql_grant/mysql.rb0000644005276200011600000001500612763636535024776 0ustar jenkinsjenkinsrequire File.expand_path(File.join(File.dirname(__FILE__), '..', 'mysql')) Puppet::Type.type(:mysql_grant).provide(:mysql, :parent => Puppet::Provider::Mysql) do desc 'Set grants for users in MySQL.' def self.instances instances = [] users.select{ |user| user =~ /.+@/ }.collect do |user| user_string = self.cmd_user(user) query = "SHOW GRANTS FOR #{user_string};" begin grants = mysql([defaults_file, "-NBe", query].compact) rescue Puppet::ExecutionFailure => e # Silently ignore users with no grants. Can happen e.g. if user is # defined with fqdn and server is run with skip-name-resolve. Example: # Default root user created by mysql_install_db on a host with fqdn # of myhost.mydomain.my: root@myhost.mydomain.my, when MySQL is started # with --skip-name-resolve. if e.inspect =~ /There is no such grant defined for user/ next else raise Puppet::Error, "#mysql had an error -> #{e.inspect}" end end # Once we have the list of grants generate entries for each. grants.each_line do |grant| # Match the munges we do in the type. munged_grant = grant.delete("'").delete("`").delete('"') # Matching: GRANT (SELECT, UPDATE) PRIVILEGES ON (*.*) TO ('root')@('127.0.0.1') (WITH GRANT OPTION) if match = munged_grant.match(/^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)?$/) privileges, table, user, host, rest = match.captures table.gsub!('\\\\', '\\') # split on ',' if it is not a non-'('-containing string followed by a # closing parenthesis ')'-char - e.g. only split comma separated elements not in # parentheses stripped_privileges = privileges.strip.split(/\s*,\s*(?![^(]*\))/).map do |priv| # split and sort the column_privileges in the parentheses and rejoin if priv.include?('(') type, col=priv.strip.split(/\s+|\b/,2) type.upcase + " (" + col.slice(1...-1).strip.split(/\s*,\s*/).sort.join(', ') + ")" else # Once we split privileges up on the , we need to make sure we # shortern ALL PRIVILEGES to just all. priv == 'ALL PRIVILEGES' ? 'ALL' : priv.strip end end # Same here, but to remove OPTION leaving just GRANT. if rest.match(/WITH\sGRANT\sOPTION/) options = ['GRANT'] else options = ['NONE'] end # fix double backslash that MySQL prints, so resources match table.gsub!("\\\\", "\\") # We need to return an array of instances so capture these instances << new( :name => "#{user}@#{host}/#{table}", :ensure => :present, :privileges => stripped_privileges.sort, :table => table, :user => "#{user}@#{host}", :options => options ) end end end return instances end def self.prefetch(resources) users = instances resources.keys.each do |name| if provider = users.find { |user| user.name == name } resources[name].provider = provider end end end def grant(user, table, privileges, options) user_string = self.class.cmd_user(user) priv_string = self.class.cmd_privs(privileges) table_string = self.class.cmd_table(table) query = "GRANT #{priv_string}" query << " ON #{table_string}" query << " TO #{user_string}" query << self.class.cmd_options(options) unless options.nil? mysql([defaults_file, system_database, '-e', query].compact) end def create grant(@resource[:user], @resource[:table], @resource[:privileges], @resource[:options]) @property_hash[:ensure] = :present @property_hash[:table] = @resource[:table] @property_hash[:user] = @resource[:user] @property_hash[:options] = @resource[:options] if @resource[:options] @property_hash[:privileges] = @resource[:privileges] exists? ? (return true) : (return false) end def revoke(user, table, revoke_privileges = ['ALL']) user_string = self.class.cmd_user(user) table_string = self.class.cmd_table(table) priv_string = self.class.cmd_privs(revoke_privileges) # revoke grant option needs to be a extra query, because # "REVOKE ALL PRIVILEGES, GRANT OPTION [..]" is only valid mysql syntax # if no ON clause is used. # It hast to be executed before "REVOKE ALL [..]" since a GRANT has to # exist to be executed successfully if revoke_privileges.include? 'ALL' query = "REVOKE GRANT OPTION ON #{table_string} FROM #{user_string}" mysql([defaults_file, system_database, '-e', query].compact) end query = "REVOKE #{priv_string} ON #{table_string} FROM #{user_string}" mysql([defaults_file, system_database, '-e', query].compact) end def destroy # if the user was dropped, it'll have been removed from the user hash # as the grants are alraedy removed by the DROP statement if self.class.users.include? @property_hash[:user] revoke(@property_hash[:user], @property_hash[:table]) end @property_hash.clear exists? ? (return false) : (return true) end def exists? @property_hash[:ensure] == :present || false end def flush @property_hash.clear mysql([defaults_file, '-NBe', 'FLUSH PRIVILEGES'].compact) end mk_resource_methods def diff_privileges(privileges_old, privileges_new) diff = {:revoke => Array.new, :grant => Array.new} if privileges_old.include? 'ALL' diff[:revoke] = privileges_old diff[:grant] = privileges_new elsif privileges_new.include? 'ALL' diff[:grant] = privileges_new else diff[:revoke] = privileges_old - privileges_new diff[:grant] = privileges_new - privileges_old end return diff end def privileges=(privileges) diff = diff_privileges(@property_hash[:privileges], privileges) if not diff[:revoke].empty? revoke(@property_hash[:user], @property_hash[:table], diff[:revoke]) end if not diff[:grant].empty? grant(@property_hash[:user], @property_hash[:table], diff[:grant], @property_hash[:options]) end @property_hash[:privileges] = privileges self.privileges end def options=(options) revoke(@property_hash[:user], @property_hash[:table]) grant(@property_hash[:user], @property_hash[:table], @property_hash[:privileges], options) @property_hash[:options] = options self.options end end puppetlabs-mysql-3.10.0/templates/0000755005276200011600000000000013010160602016770 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/templates/xtrabackup.sh.erb0000644005276200011600000000055012746170223022256 0ustar jenkinsjenkins<%- if @kernel == 'Linux' -%> #!/bin/bash <%- else -%> #!/bin/sh <%- end -%> # # A wrapper for Xtrabackup # <% if @prescript -%> <%- [@prescript].flatten.compact.each do |script| %> <%= script %> <%- end -%> <% end -%> innobackupex "$@" <% if @postscript -%> <%- [@postscript].flatten.compact.each do |script| %> <%= script %> <%- end -%> <% end -%> puppetlabs-mysql-3.10.0/templates/meb.cnf.erb0000644005276200011600000000067212746170223021016 0ustar jenkinsjenkins### MANAGED BY PUPPET ### <% @options.sort.map do |k,v| -%> <% if v.is_a?(Hash) -%> [<%= k %>] <% v.sort.map do |ki, vi| -%> <% if vi == true or v == '' -%> <%= ki %> <% elsif vi.is_a?(Array) -%> <% vi.each do |vii| -%> <%= ki %> = <%= vii %> <% end -%> <% elsif ![nil, '', :undef].include?(vi) -%> <%= ki %> = <%= vi %> <% end -%> <% end -%> <% end %> <% end -%> puppetlabs-mysql-3.10.0/templates/my.cnf.erb0000644005276200011600000000117112746170223020673 0ustar jenkinsjenkins### MANAGED BY PUPPET ### <% @options.sort.map do |k,v| -%> <% if v.is_a?(Hash) -%> [<%= k %>] <% v.sort.map do |ki, vi| -%> <% if ki == 'ssl-disable' or (ki =~ /^ssl/ and v['ssl-disable'] == true) -%> <% next %> <% elsif vi == true or vi == '' -%> <%= ki %> <% elsif vi.is_a?(Array) -%> <% vi.each do |vii| -%> <%= ki %> = <%= vii %> <% end -%> <% elsif ![nil, '', :undef].include?(vi) -%> <%= ki %> = <%= vi %> <% end -%> <% end -%> <% end %> <% end -%> <% if @includedir and @includedir != '' %> !includedir <%= @includedir %> <% end %> puppetlabs-mysql-3.10.0/templates/my.cnf.pass.erb0000644005276200011600000000053212746170223021640 0ustar jenkinsjenkins### MANAGED BY PUPPET ### <% %w(mysql client mysqldump mysqladmin mysqlcheck).each do |section| %> [<%= section -%>] user=root host=localhost <% unless scope.lookupvar('mysql::server::root_password') == 'UNSET' -%> password='<%= scope.lookupvar('mysql::server::root_password') %>' <% end -%> socket=<%= @options['client']['socket'] %> <% end %> puppetlabs-mysql-3.10.0/templates/mysqlbackup.sh.erb0000755005276200011600000000602012763636535022462 0ustar jenkinsjenkins<%- if @kernel == 'Linux' -%> #!/bin/bash <%- else -%> #!/bin/sh <%- end -%> # # MySQL Backup Script # Dumps mysql databases to a file for another backup tool to pick up. # # MySQL code: # GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost' # IDENTIFIED BY 'password'; # FLUSH PRIVILEGES; # ##### START CONFIG ################################################### USER=<%= @backupuser %> PASS='<%= @backuppassword %>' MAX_ALLOWED_PACKET=<%= @maxallowedpacket %> DIR=<%= @backupdir %> ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %> # Create temporary mysql cnf file. TMPFILE=`mktemp /tmp/backup.XXXXXX` || exit 1 echo -e "[client]\npassword=$PASS\nuser=$USER\nmax_allowed_packet=$MAX_ALLOWED_PACKET" > $TMPFILE # Ensure backup directory exist. mkdir -p $DIR PREFIX=mysql_backup_ <% if @ignore_events %> ADDITIONAL_OPTIONS="--ignore-table=mysql.event" <% else %> ADDITIONAL_OPTIONS="--events" <% end %> <%# Only include routines or triggers if we're doing a file per database -%> <%# backup. This happens if we named databases, or if we explicitly set -%> <%# file per database mode -%> <% if !@backupdatabases.empty? || @file_per_database -%> <% if @include_triggers -%> ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --triggers" <% else -%> ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --skip-triggers" <% end -%> <% if @include_routines -%> ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --routines" <% else -%> ADDITIONAL_OPTIONS="$ADDITIONAL_OPTIONS --skip-routines" <% end -%> <% end -%> ##### STOP CONFIG #################################################### PATH=<%= @execpath %> <%- if @kernel == 'Linux' -%> set -o pipefail <%- end -%> cleanup() { find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f } <% if @delete_before_dump -%> cleanup <% end -%> <% if @backupdatabases.empty? -%> <% if @file_per_database -%> mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname do mysqldump --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ ${ADDITIONAL_OPTIONS} \ ${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> done <% else -%> mysqldump --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ ${ADDITIONAL_OPTIONS} \ --all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> <% end -%> <% else -%> <% @backupdatabases.each do |db| -%> mysqldump --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ ${ADDITIONAL_OPTIONS} \ <%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> <% end -%> <% end -%> <% unless @delete_before_dump -%> if [ $? -eq 0 ] ; then cleanup fi <% end -%> <% if @postscript -%> <%- [@postscript].flatten.compact.each do |script|%> <%= script %> <%- end -%> <% end -%> # Remove temporary file rm -f $TMPFILE puppetlabs-mysql-3.10.0/TODO0000644005276200011600000000071612746170216015507 0ustar jenkinsjenkinsThe best that I can tell is that this code traces back to David Schmitt. It has been forked many times since then :) 1. you cannot add databases to an instance that has a root password 2. you have to specify username as USER@BLAH or it cannot be found 3. mysql_grant does not complain if user does not exist 4. Needs support for pre-seeding on debian 5. the types may need to take user/password 6. rather or not to configure /etc/.my.cnf should be configurable puppetlabs-mysql-3.10.0/Rakefile0000644005276200011600000000227512763636535016500 0ustar jenkinsjenkinsrequire 'puppet_blacksmith/rake_tasks' require 'puppet-lint/tasks/puppet-lint' require 'puppetlabs_spec_helper/rake_tasks' PuppetLint.configuration.send('relative') PuppetLint.configuration.send('disable_documentation') PuppetLint.configuration.send('disable_single_quote_string_with_variables') desc 'Generate pooler nodesets' task :gen_nodeset do require 'beaker-hostgenerator' require 'securerandom' require 'fileutils' agent_target = ENV['TEST_TARGET'] if ! agent_target STDERR.puts 'TEST_TARGET environment variable is not set' STDERR.puts 'setting to default value of "redhat-64default."' agent_target = 'redhat-64default.' end master_target = ENV['MASTER_TEST_TARGET'] if ! master_target STDERR.puts 'MASTER_TEST_TARGET environment variable is not set' STDERR.puts 'setting to default value of "redhat7-64mdcl"' master_target = 'redhat7-64mdcl' end targets = "#{master_target}-#{agent_target}" cli = BeakerHostGenerator::CLI.new([targets]) nodeset_dir = "tmp/nodesets" nodeset = "#{nodeset_dir}/#{targets}-#{SecureRandom.uuid}.yaml" FileUtils.mkdir_p(nodeset_dir) File.open(nodeset, 'w') do |fh| fh.print(cli.execute) end puts nodeset end puppetlabs-mysql-3.10.0/spec/0000755005276200011600000000000013010160602015724 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/classes/0000755005276200011600000000000013010160602017361 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/classes/mysql_bindings_spec.rb0000644005276200011600000000203212746170223023756 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'mysql::bindings' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts.merge({ :root_home => '/root', }) } let(:params) {{ 'java_enable' => true, 'perl_enable' => true, 'php_enable' => true, 'python_enable' => true, 'ruby_enable' => true, 'client_dev' => true, 'daemon_dev' => true, 'client_dev_package_name' => 'libmysqlclient-devel', 'daemon_dev_package_name' => 'mysql-devel', }} it { is_expected.to contain_package('mysql-connector-java') } it { is_expected.to contain_package('perl_mysql') } it { is_expected.to contain_package('python-mysqldb') } it { is_expected.to contain_package('ruby_mysql') } it { is_expected.to contain_package('mysql-client_dev') } it { is_expected.to contain_package('mysql-daemon_dev') } end end end puppetlabs-mysql-3.10.0/spec/classes/mysql_server_spec.rb0000644005276200011600000002171512763636535023514 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'mysql::server' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts.merge({ :root_home => '/root', }) } context 'with defaults' do it { is_expected.to contain_class('mysql::server::install') } it { is_expected.to contain_class('mysql::server::config') } it { is_expected.to contain_class('mysql::server::service') } it { is_expected.to contain_class('mysql::server::root_password') } it { is_expected.to contain_class('mysql::server::providers') } end context 'with remove_default_accounts set' do let(:params) {{ :remove_default_accounts => true }} it { is_expected.to contain_class('mysql::server::account_security') } end context 'when not managing config file' do let(:params) {{ :manage_config_file => false }} it { is_expected.to compile.with_all_deps } end context 'when not managing the service' do let(:params) {{ :service_manage => false }} it { is_expected.to compile.with_all_deps } it { is_expected.not_to contain_service('mysqld') } end context 'mysql::server::install' do it 'contains the package by default' do is_expected.to contain_package('mysql-server').with({ :ensure => :present, }) end context 'with package_manage set to true' do let(:params) {{ :package_manage => true }} it { is_expected.to contain_package('mysql-server') } end context 'with package_manage set to false' do let(:params) {{ :package_manage => false }} it { is_expected.not_to contain_package('mysql-server') } end context 'with datadir overridden' do let(:params) {{ :override_options => { 'mysqld' => { 'datadir' => '/tmp' }} }} it { is_expected.to contain_mysql_datadir('/tmp') } end end context 'mysql::server::service' do context 'with defaults' do it { is_expected.to contain_service('mysqld') } end context 'with package_manage set to true' do let(:params) {{ :package_manage => true }} it { is_expected.to contain_service('mysqld').that_requires('Package[mysql-server]') } end context 'with package_manage set to false' do let(:params) {{ :package_manage => false }} it { is_expected.to contain_service('mysqld') } it { is_expected.not_to contain_service('mysqld').that_requires('Package[mysql-server]') } end context 'service_enabled set to false' do let(:params) {{ :service_enabled => false }} it do is_expected.to contain_service('mysqld').with({ :ensure => :stopped }) end context 'with package_manage set to true' do let(:params) {{ :package_manage => true }} it { is_expected.to contain_package('mysql-server') } end context 'with package_manage set to false' do let(:params) {{ :package_manage => false }} it { is_expected.not_to contain_package('mysql-server') } end context 'with datadir overridden' do let(:params) {{ :override_options => { 'mysqld' => { 'datadir' => '/tmp' }} }} it { is_expected.to contain_mysql_datadir('/tmp') } end end context 'with log-error overridden' do let(:params) {{ :override_options => { 'mysqld' => { 'log-error' => '/tmp/error.log' }} }} it { is_expected.to contain_file('/tmp/error.log') } end end context 'mysql::server::root_password' do describe 'when defaults' do it { is_expected.to contain_exec('remove install pass').with( :command => 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /.mysql_secret) password \'\' && rm -f /.mysql_secret', :onlyif => 'test -f /.mysql_secret', :path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin' ) } it { is_expected.not_to contain_mysql_user('root@localhost') } it { is_expected.not_to contain_file('/root/.my.cnf') } end describe 'when root_password set' do let(:params) {{:root_password => 'SET' }} it { is_expected.to contain_mysql_user('root@localhost') } if Puppet.version.to_f >= 3.0 it { is_expected.to contain_file('/root/.my.cnf').with(:show_diff => false).that_requires('Mysql_user[root@localhost]') } else it { is_expected.to contain_file('/root/.my.cnf').that_requires('Mysql_user[root@localhost]') } end end describe 'when root_password set, create_root_user set to false' do let(:params) {{ :root_password => 'SET', :create_root_user => false }} it { is_expected.not_to contain_mysql_user('root@localhost') } if Puppet.version.to_f >= 3.0 it { is_expected.to contain_file('/root/.my.cnf').with(:show_diff => false) } else it { is_expected.to contain_file('/root/.my.cnf') } end end describe 'when root_password set, create_root_my_cnf set to false' do let(:params) {{ :root_password => 'SET', :create_root_my_cnf => false }} it { is_expected.to contain_mysql_user('root@localhost') } it { is_expected.not_to contain_file('/root/.my.cnf') } end describe 'when root_password set, create_root_user and create_root_my_cnf set to false' do let(:params) {{ :root_password => 'SET', :create_root_user => false, :create_root_my_cnf => false }} it { is_expected.not_to contain_mysql_user('root@localhost') } it { is_expected.not_to contain_file('/root/.my.cnf') } end describe 'when install_secret_file set to /root/.mysql_secret' do let(:params) {{ :install_secret_file => '/root/.mysql_secret' }} it { is_expected.to contain_exec('remove install pass').with( :command => 'mysqladmin -u root --password=$(grep -o \'[^ ]\\+$\' /root/.mysql_secret) password \'\' && rm -f /root/.mysql_secret', :onlyif => 'test -f /root/.mysql_secret' ) } end end context 'mysql::server::providers' do describe 'with users' do let(:params) {{:users => { 'foo@localhost' => { 'max_connections_per_hour' => '1', 'max_queries_per_hour' => '2', 'max_updates_per_hour' => '3', 'max_user_connections' => '4', 'password_hash' => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF' }, 'foo2@localhost' => {} }}} it { is_expected.to contain_mysql_user('foo@localhost').with( :max_connections_per_hour => '1', :max_queries_per_hour => '2', :max_updates_per_hour => '3', :max_user_connections => '4', :password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF' )} it { is_expected.to contain_mysql_user('foo2@localhost').with( :max_connections_per_hour => nil, :max_queries_per_hour => nil, :max_updates_per_hour => nil, :max_user_connections => nil, :password_hash => nil )} end describe 'with grants' do let(:params) {{:grants => { 'foo@localhost/somedb.*' => { 'user' => 'foo@localhost', 'table' => 'somedb.*', 'privileges' => ["SELECT", "UPDATE"], 'options' => ["GRANT"], }, 'foo2@localhost/*.*' => { 'user' => 'foo2@localhost', 'table' => '*.*', 'privileges' => ["SELECT"], }, }}} it { is_expected.to contain_mysql_grant('foo@localhost/somedb.*').with( :user => 'foo@localhost', :table => 'somedb.*', :privileges => ["SELECT", "UPDATE"], :options => ["GRANT"] )} it { is_expected.to contain_mysql_grant('foo2@localhost/*.*').with( :user => 'foo2@localhost', :table => '*.*', :privileges => ["SELECT"], :options => nil )} end describe 'with databases' do let(:params) {{:databases => { 'somedb' => { 'charset' => 'latin1', 'collate' => 'latin1', }, 'somedb2' => {} }}} it { is_expected.to contain_mysql_database('somedb').with( :charset => 'latin1', :collate => 'latin1' )} it { is_expected.to contain_mysql_database('somedb2')} end end end end end puppetlabs-mysql-3.10.0/spec/classes/mysql_server_mysqltuner_spec.rb0000644005276200011600000000253712746170223026004 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'mysql::server::mysqltuner' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts.merge({ :staging_http_get => 'curl', :root_home => '/root', }) } context 'ensure => present' do it { is_expected.to compile } it { is_expected.to contain_staging__file('mysqltuner-v1.3.0').with({ :source => 'https://github.com/major/MySQLTuner-perl/raw/v1.3.0/mysqltuner.pl', }) } end context 'ensure => absent' do let(:params) {{ :ensure => 'absent' }} it { is_expected.to compile } it { is_expected.to contain_file('/usr/local/bin/mysqltuner').with(:ensure => 'absent') } end context 'custom version' do let(:params) {{ :version => 'v1.2.0' }} it { is_expected.to compile } it { is_expected.to contain_staging__file('mysqltuner-v1.2.0').with({ :source => 'https://github.com/major/MySQLTuner-perl/raw/v1.2.0/mysqltuner.pl', }) } end context 'custom source' do let(:params) {{ :source => '/tmp/foo' }} it { is_expected.to compile } it { is_expected.to contain_staging__file('mysqltuner-/tmp/foo').with({ :source => '/tmp/foo', }) } end end end end puppetlabs-mysql-3.10.0/spec/classes/graceful_failures_spec.rb0000644005276200011600000000065312746170223024425 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'mysql::server' do context "on an unsupported OS" do # fetch any sets of facts to modify them os, facts = on_supported_os.first let(:facts) { facts.merge({ :osfamily => 'UNSUPPORTED', :operatingsystem => 'UNSUPPORTED', }) } it 'should gracefully fail' do is_expected.to compile.and_raise_error(/Unsupported platform:/) end end end puppetlabs-mysql-3.10.0/spec/classes/mysql_server_monitor_spec.rb0000644005276200011600000000171412746170223025244 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'mysql::server::monitor' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts.merge({ :root_home => '/root', }) } let :pre_condition do "include 'mysql::server'" end let :default_params do { :mysql_monitor_username => 'monitoruser', :mysql_monitor_password => 'monitorpass', :mysql_monitor_hostname => 'monitorhost', } end let :params do default_params end it { is_expected.to contain_mysql_user('monitoruser@monitorhost')} it { is_expected.to contain_mysql_grant('monitoruser@monitorhost/*.*').with( :ensure => 'present', :user => 'monitoruser@monitorhost', :table => '*.*', :privileges => ["PROCESS", "SUPER"], :require => 'Mysql_user[monitoruser@monitorhost]' )} end end end puppetlabs-mysql-3.10.0/spec/classes/mysql_server_backup_spec.rb0000644005276200011600000003153312763636535025040 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'mysql::server::backup' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts.merge({ :root_home => '/root', }) } let(:default_params) { { 'backupuser' => 'testuser', 'backuppassword' => 'testpass', 'maxallowedpacket' => '1M', 'backupdir' => '/tmp', 'backuprotate' => '25', 'delete_before_dump' => true, 'execpath' => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin', 'maxallowedpacket' => '1M', } } context 'standard conditions' do let(:params) { default_params } # Cannot use that_requires here, doesn't work on classes. it { is_expected.to contain_mysql_user('testuser@localhost').with( :require => 'Class[Mysql::Server::Root_password]') } it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with( :privileges => ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS'] ).that_requires('Mysql_user[testuser@localhost]') } context 'with triggers included' do let(:params) do { :include_triggers => true }.merge(default_params) end it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with( :privileges => ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS', 'TRIGGER'] ).that_requires('Mysql_user[testuser@localhost]') } end it { is_expected.to contain_cron('mysql-backup').with( :command => '/usr/local/sbin/mysqlbackup.sh', :ensure => 'present' )} it { is_expected.to contain_file('mysqlbackup.sh').with( :path => '/usr/local/sbin/mysqlbackup.sh', :ensure => 'present' ) } it { is_expected.to contain_file('mysqlbackupdir').with( :path => '/tmp', :ensure => 'directory' )} it 'should have compression by default' do is_expected.to contain_file('mysqlbackup.sh').with_content( /bzcat -zc/ ) end it 'should skip backing up events table by default' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="--ignore-table=mysql.event"/ ) end it 'should not mention triggers by default because file_per_database is false' do is_expected.to contain_file('mysqlbackup.sh').without_content( /.*triggers.*/ ) end it 'should not mention routines by default because file_per_database is false' do is_expected.to contain_file('mysqlbackup.sh').without_content( /.*routines.*/ ) end it 'should have 25 days of rotation' do # MySQL counts from 0 is_expected.to contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/) end it 'should have a standard PATH' do is_expected.to contain_file('mysqlbackup.sh').with_content(%r{PATH=/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin}) end end context 'custom ownership and mode for backupdir' do let(:params) do { :backupdirmode => '0750', :backupdirowner => 'testuser', :backupdirgroup => 'testgrp', }.merge(default_params) end it { is_expected.to contain_file('mysqlbackupdir').with( :path => '/tmp', :ensure => 'directory', :mode => '0750', :owner => 'testuser', :group => 'testgrp' ) } end context 'with compression disabled' do let(:params) do { :backupcompress => false }.merge(default_params) end it { is_expected.to contain_file('mysqlbackup.sh').with( :path => '/usr/local/sbin/mysqlbackup.sh', :ensure => 'present' ) } it 'should be able to disable compression' do is_expected.to contain_file('mysqlbackup.sh').without_content( /.*bzcat -zc.*/ ) end end context 'with mysql.events backedup' do let(:params) do { :ignore_events => false }.merge(default_params) end it { is_expected.to contain_file('mysqlbackup.sh').with( :path => '/usr/local/sbin/mysqlbackup.sh', :ensure => 'present' ) } it 'should be able to backup events table' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="--events"/ ) end end context 'with database list specified' do let(:params) do { :backupdatabases => ['mysql'] }.merge(default_params) end it { is_expected.to contain_file('mysqlbackup.sh').with( :path => '/usr/local/sbin/mysqlbackup.sh', :ensure => 'present' ) } it 'should have a backup file for each database' do is_expected.to contain_file('mysqlbackup.sh').with_content( /mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date'/ ) end it 'should skip backup triggers by default' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/ ) end it 'should skip backing up routines by default' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/ ) end context 'with include_triggers set to true' do let(:params) do default_params.merge({ :backupdatabases => ['mysql'], :include_triggers => true }) end it 'should backup triggers when asked' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --triggers"/ ) end end context 'with include_triggers set to false' do let(:params) do default_params.merge({ :backupdatabases => ['mysql'], :include_triggers => false }) end it 'should skip backing up triggers when asked to skip' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/ ) end end context 'with include_routines set to true' do let(:params) do default_params.merge({ :backupdatabases => ['mysql'], :include_routines => true }) end it 'should backup routines when asked' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --routines"/ ) end end context 'with include_routines set to false' do let(:params) do default_params.merge({ :backupdatabases => ['mysql'], :include_triggers => true }) end it 'should skip backing up routines when asked to skip' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/ ) end end end context 'with file per database' do let(:params) do default_params.merge({ :file_per_database => true }) end it 'should loop through backup all databases' do is_expected.to contain_file('mysqlbackup.sh').with_content(/.*SHOW DATABASES.*/) end context 'with compression disabled' do let(:params) do default_params.merge({ :file_per_database => true, :backupcompress => false }) end it 'should loop through backup all databases without compression' do is_expected.to contain_file('mysqlbackup.sh').with_content( /.*SHOW DATABASES.*/ ) is_expected.to contain_file('mysqlbackup.sh').without_content( /.*bzcat -zc.*/ ) end end it 'should skip backup triggers by default' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/ ) end it 'should skip backing up routines by default' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/ ) end context 'with include_triggers set to true' do let(:params) do default_params.merge({ :file_per_database => true, :include_triggers => true }) end it 'should backup triggers when asked' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --triggers"/ ) end end context 'with include_triggers set to false' do let(:params) do default_params.merge({ :file_per_database => true, :include_triggers => false }) end it 'should skip backing up triggers when asked to skip' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-triggers"/ ) end end context 'with include_routines set to true' do let(:params) do default_params.merge({ :file_per_database => true, :include_routines => true }) end it 'should backup routines when asked' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --routines"/ ) end end context 'with include_routines set to false' do let(:params) do default_params.merge({ :file_per_database => true, :include_triggers => true }) end it 'should skip backing up routines when asked to skip' do is_expected.to contain_file('mysqlbackup.sh').with_content( /ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --skip-routines"/ ) end end end context 'with postscript' do let(:params) do default_params.merge({ :postscript => 'rsync -a /tmp backup01.local-lan:' }) end it 'should be add postscript' do is_expected.to contain_file('mysqlbackup.sh').with_content( /rsync -a \/tmp backup01.local-lan:/ ) end end context 'with postscripts' do let(:params) do default_params.merge({ :postscript => [ 'rsync -a /tmp backup01.local-lan:', 'rsync -a /tmp backup02.local-lan:', ]}) end it 'should be add postscript' do is_expected.to contain_file('mysqlbackup.sh').with_content( /.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/ ) end end context 'with the xtrabackup provider' do let(:params) do default_params.merge({:provider => 'xtrabackup'}) end it 'should contain the wrapper script' do is_expected.to contain_file('xtrabackup.sh').with_content( /^innobackupex\s+"\$@"/ ) end context 'with prescript defined' do let(:params) do default_params.merge({ :provider => 'xtrabackup', :prescript => [ 'rsync -a /tmp backup01.local-lan:', 'rsync -a /tmp backup02.local-lan:', ] }) end it 'should contain the prescript' do is_expected.to contain_file('xtrabackup.sh').with_content( /.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/ ) end end context 'with postscript defined' do let(:params) do default_params.merge({ :provider => 'xtrabackup', :postscript => [ 'rsync -a /tmp backup01.local-lan:', 'rsync -a /tmp backup02.local-lan:', ] }) end it 'should contain the prostscript' do is_expected.to contain_file('xtrabackup.sh').with_content( /.*rsync -a \/tmp backup01.local-lan:\n\nrsync -a \/tmp backup02.local-lan:.*/ ) end end end end end end puppetlabs-mysql-3.10.0/spec/classes/mysql_server_account_security_spec.rb0000644005276200011600000000452512746170223027143 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'mysql::server::account_security' do on_supported_os.each do |os, facts| context "on #{os}" do context "with fqdn==myhost.mydomain" do let(:facts) { facts.merge({ :root_home => '/root', :fqdn => 'myhost.mydomain', :hostname => 'myhost', }) } [ 'root@myhost.mydomain', 'root@127.0.0.1', 'root@::1', '@myhost.mydomain', '@localhost', '@%', ].each do |user| it "removes Mysql_User[#{user}]" do is_expected.to contain_mysql_user(user).with_ensure('absent') end end # When the hostname doesn't match the fqdn we also remove these. # We don't need to test the inverse as when they match they are # covered by the above list. [ 'root@myhost', '@myhost' ].each do |user| it "removes Mysql_User[#{user}]" do is_expected.to contain_mysql_user(user).with_ensure('absent') end end it 'should remove Mysql_database[test]' do is_expected.to contain_mysql_database('test').with_ensure('absent') end end context "with fqdn==localhost" do let(:facts) { facts.merge({ :root_home => '/root', :fqdn => 'localhost', :hostname => 'localhost', }) } [ 'root@127.0.0.1', 'root@::1', '@localhost', 'root@localhost.localdomain', '@localhost.localdomain', '@%', ].each do |user| it "removes Mysql_User[#{user}]" do is_expected.to contain_mysql_user(user).with_ensure('absent') end end end context "with fqdn==localhost.localdomain" do let(:facts) { facts.merge({ :root_home => '/root', :fqdn => 'localhost.localdomain', :hostname => 'localhost', }) } [ 'root@127.0.0.1', 'root@::1', '@localhost', 'root@localhost.localdomain', '@localhost.localdomain', '@%', ].each do |user| it "removes Mysql_User[#{user}]" do is_expected.to contain_mysql_user(user).with_ensure('absent') end end end end end end puppetlabs-mysql-3.10.0/spec/classes/mysql_client_spec.rb0000644005276200011600000000173512746170223023450 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'mysql::client' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts.merge({ :root_home => '/root', }) } context 'with defaults' do it { is_expected.not_to contain_class('mysql::bindings') } it { is_expected.to contain_package('mysql_client') } end context 'with bindings enabled' do let(:params) {{ :bindings_enable => true }} it { is_expected.to contain_class('mysql::bindings') } it { is_expected.to contain_package('mysql_client') } end context 'with package_manage set to true' do let(:params) {{ :package_manage => true }} it { is_expected.to contain_package('mysql_client') } end context 'with package_manage set to false' do let(:params) {{ :package_manage => false }} it { is_expected.not_to contain_package('mysql_client') } end end end end puppetlabs-mysql-3.10.0/spec/classes/mycnf_template_spec.rb0000644005276200011600000000644312746170223023755 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'mysql::server' do context 'my.cnf template' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts.merge({ :root_home => '/root', }) } context 'normal entry' do let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }} it do is_expected.to contain_file('mysql-config-file').with({ :mode => '0644', :selinux_ignore_defaults => true, }).with_content(/socket = \/var\/lib\/mysql\/mysql.sock/) end end describe 'array entry' do let(:params) {{ :override_options => { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2'], } }}} it do is_expected.to contain_file('mysql-config-file').with_content( /.*replicate-do-db = base1\nreplicate-do-db = base2.*/ ) end end describe 'skip-name-resolve set to an empty string' do let(:params) {{ :override_options => { 'mysqld' => { 'skip-name-resolve' => '' }}}} it { is_expected.to contain_file('mysql-config-file').with_content(/^skip-name-resolve$/) } end describe 'ssl set to true' do let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true }}}} it { is_expected.to contain_file('mysql-config-file').with_content(/ssl/) } it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) } end describe 'ssl set to false' do let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => false }}}} it { is_expected.to contain_file('mysql-config-file').with_content(/ssl = false/) } end # ssl-disable (and ssl) are special cased within mysql. describe 'possibility of disabling ssl completely' do let(:params) {{ :override_options => { 'mysqld' => { 'ssl' => true, 'ssl-disable' => true }}}} it { is_expected.to contain_file('mysql-config-file').without_content(/ssl = true/) } end describe 'a non ssl option set to true' do let(:params) {{ :override_options => { 'mysqld' => { 'test' => true }}}} it { is_expected.to contain_file('mysql-config-file').with_content(/^test$/) } it { is_expected.to contain_file('mysql-config-file').without_content(/test = true/) } end context 'with includedir' do let(:params) {{ :includedir => '/etc/my.cnf.d' }} it 'makes the directory' do is_expected.to contain_file('/etc/my.cnf.d').with({ :ensure => :directory, :mode => '0755', }) end it { is_expected.to contain_file('mysql-config-file').with_content(/!includedir/) } end context 'without includedir' do let(:params) {{ :includedir => '' }} it 'shouldnt contain the directory' do is_expected.not_to contain_file('mysql-config-file').with({ :ensure => :directory, :mode => '0755', }) end it { is_expected.to contain_file('mysql-config-file').without_content(/!includedir/) } end end end end end puppetlabs-mysql-3.10.0/spec/spec.opts0000644005276200011600000000005712746170216017610 0ustar jenkinsjenkins--format s --colour --loadby mtime --backtrace puppetlabs-mysql-3.10.0/spec/acceptance/0000755005276200011600000000000013010160602020012 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/acceptance/mysql_server_spec.rb0000644005276200011600000000702212763636535024140 0ustar jenkinsjenkinsrequire 'spec_helper_acceptance' describe 'mysql class' do describe 'advanced config' do before(:all) do @tmpdir = default.tmpdir('mysql') end let(:pp) do <<-EOS class { 'mysql::server': config_file => '#{@tmpdir}/my.cnf', includedir => '#{@tmpdir}/include', manage_config_file => 'true', override_options => { 'mysqld' => { 'key_buffer_size' => '32M' }}, package_ensure => 'present', purge_conf_dir => 'true', remove_default_accounts => 'true', restart => 'true', root_group => 'root', root_password => 'test', service_enabled => 'true', service_manage => 'true', users => { 'someuser@localhost' => { ensure => 'present', max_connections_per_hour => '0', max_queries_per_hour => '0', max_updates_per_hour => '0', max_user_connections => '0', password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF', }}, grants => { 'someuser@localhost/somedb.*' => { ensure => 'present', options => ['GRANT'], privileges => ['SELECT', 'INSERT', 'UPDATE', 'DELETE'], table => 'somedb.*', user => 'someuser@localhost', }, }, databases => { 'somedb' => { ensure => 'present', charset => 'utf8', }, } } EOS end it_behaves_like "a idempotent resource" end describe 'minimal config' do before(:all) do @tmpdir = default.tmpdir('mysql') end let(:pp) do <<-EOS class { 'mysql::server': config_file => '#{@tmpdir}/my.cnf', includedir => '#{@tmpdir}/include', manage_config_file => 'false', override_options => { 'mysqld' => { 'key_buffer_size' => '32M' }}, package_ensure => 'present', purge_conf_dir => 'false', remove_default_accounts => 'false', restart => 'false', root_group => 'root', root_password => 'test', service_enabled => 'false', service_manage => 'false', users => {}, grants => {}, databases => {}, } EOS end it_behaves_like "a idempotent resource" end describe 'syslog configuration' do let(:pp) do <<-EOS class { 'mysql::server': override_options => { 'mysqld' => { 'log-error' => undef }, 'mysqld_safe' => { 'log-error' => false, 'syslog' => true }}, } EOS end it_behaves_like "a idempotent resource" end context 'when changing the password' do let(:password) { 'THE NEW SECRET' } let(:pp) { "class { 'mysql::server': root_password => '#{password}' }" } it 'should not display the password' do result = apply_manifest(pp, :catch_failures => true) # this does not actually prove anything, as show_diff in the puppet config defaults to false. expect(result.stdout).not_to match /#{password}/ end it_behaves_like "a idempotent resource" end end puppetlabs-mysql-3.10.0/spec/acceptance/types/0000755005276200011600000000000013010160602021156 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/acceptance/types/mysql_plugin_spec.rb0000644005276200011600000000471212763636535025277 0ustar jenkinsjenkinsrequire 'spec_helper_acceptance' # Different operating systems (and therefore different versions/forks # of mysql) have varying levels of support for plugins and have # different plugins available. Choose a plugin that works or don't try # to test plugins if not available. if fact('osfamily') =~ /RedHat/ if fact('operatingsystemrelease') =~ /^5\./ plugin = nil # Plugins not supported on mysql on RHEL 5 elsif fact('operatingsystemrelease') =~ /^6\./ plugin = 'example' plugin_lib = 'ha_example.so' elsif fact('operatingsystemrelease') =~ /^7\./ plugin = 'pam' plugin_lib = 'auth_pam.so' end elsif fact('osfamily') =~ /Debian/ if fact('operatingsystem') =~ /Debian/ if fact('operatingsystemrelease') =~ /^6\./ # Only available plugin is innodb which is already loaded and not unload- or reload-able plugin = nil elsif fact('operatingsystemrelease') =~ /^7\./ plugin = 'example' plugin_lib = 'ha_example.so' end elsif fact('operatingsystem') =~ /Ubuntu/ if fact('operatingsystemrelease') =~ /^10\.04/ # Only available plugin is innodb which is already loaded and not unload- or reload-able plugin = nil elsif fact('operatingsystemrelease') =~ /^16\.04/ # On Xenial running 5.7.12, the example plugin does not appear to be available. plugin = 'validate_password' plugin_lib = 'validate_password.so' else plugin = 'example' plugin_lib = 'ha_example.so' end end elsif fact('osfamily') =~ /Suse/ plugin = nil # Plugin library path is broken on Suse http://lists.opensuse.org/opensuse-bugs/2013-08/msg01123.html end describe 'mysql_plugin' do if plugin # if plugins are supported describe 'setup' do it 'should work with no errors' do pp = <<-EOS class { 'mysql::server': } EOS apply_manifest(pp, :catch_failures => true) end end describe 'load plugin' do it 'should work without errors' do pp = <<-EOS mysql_plugin { #{plugin}: ensure => present, soname => '#{plugin_lib}', } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the plugin' do shell("mysql -NBe \"select plugin_name from information_schema.plugins where plugin_name='#{plugin}'\"") do |r| expect(r.stdout).to match(/^#{plugin}$/i) expect(r.stderr).to be_empty end end end end end puppetlabs-mysql-3.10.0/spec/acceptance/types/mysql_database_spec.rb0000644005276200011600000000331712746170223025531 0ustar jenkinsjenkinsrequire 'spec_helper_acceptance' describe 'mysql_database' do describe 'setup' do it 'should work with no errors' do pp = <<-EOS class { 'mysql::server': } EOS apply_manifest(pp, :catch_failures => true) end end describe 'creating database' do it 'should work without errors' do pp = <<-EOS mysql_database { 'spec_db': ensure => present, } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the database' do shell("mysql -NBe \"SHOW DATABASES LIKE 'spec_db'\"") do |r| expect(r.stdout).to match(/^spec_db$/) expect(r.stderr).to be_empty end end end describe 'charset and collate' do it 'should create two db of different types idempotently' do pp = <<-EOS mysql_database { 'spec_latin1': charset => 'latin1', collate => 'latin1_swedish_ci', } mysql_database { 'spec_utf8': charset => 'utf8', collate => 'utf8_general_ci', } EOS apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end it 'should find latin1 db' do shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_latin1") do |r| expect(r.stdout).to match(/^character_set_database\tlatin1\ncollation_database\tlatin1_swedish_ci$/) expect(r.stderr).to be_empty end end it 'should find utf8 db' do shell("mysql -NBe \"SHOW VARIABLES LIKE '%_database'\" spec_utf8") do |r| expect(r.stdout).to match(/^character_set_database\tutf8\ncollation_database\tutf8_general_ci$/) expect(r.stderr).to be_empty end end end end puppetlabs-mysql-3.10.0/spec/acceptance/types/mysql_user_spec.rb0000644005276200011600000001071213010160217024723 0ustar jenkinsjenkinsrequire 'spec_helper_acceptance' describe 'mysql_user' do describe 'setup' do it 'should work with no errors' do pp = <<-EOS class { 'mysql::server': } EOS apply_manifest(pp, :catch_failures => true) end end context 'using ashp@localhost' do describe 'adding user' do it 'should work without errors' do pp = <<-EOS mysql_user { 'ashp@localhost': password_hash => '*F9A8E96790775D196D12F53BCC88B8048FF62ED5', } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the user' do shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout).to match(/^1$/) expect(r.stderr).to be_empty end end it 'has no SSL options' do shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout).to match(/^\s*$/) expect(r.stderr).to be_empty end end end end context 'using ashp-dash@localhost' do describe 'adding user' do it 'should work without errors' do pp = <<-EOS mysql_user { 'ashp-dash@localhost': password_hash => '*F9A8E96790775D196D12F53BCC88B8048FF62ED5', } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the user' do shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp-dash@localhost'\"") do |r| expect(r.stdout).to match(/^1$/) expect(r.stderr).to be_empty end end end end context 'using ashp@LocalHost' do describe 'adding user' do it 'should work without errors' do pp = <<-EOS mysql_user { 'ashp@LocalHost': password_hash => '*F9A8E96790775D196D12F53BCC88B8048FF62ED5', } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the user' do shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| expect(r.stdout).to match(/^1$/) expect(r.stderr).to be_empty end end end end context 'using resource should throw no errors' do describe 'find users' do it { on default, puppet('resource mysql_user'), {:catch_failures => true} do |r| expect(r.stdout).to_not match(/Error:/) expect(r.stdout).to_not match(/must be properly quoted, invalid character:/) end } end end context 'using user-w-ssl@localhost with SSL' do describe 'adding user' do it 'should work without errors' do pp = <<-EOS mysql_user { 'user-w-ssl@localhost': password_hash => '*F9A8E96790775D196D12F53BCC88B8048FF62ED5', tls_options => ['SSL'], } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the user' do shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| expect(r.stdout).to match(/^1$/) expect(r.stderr).to be_empty end end it 'should show correct ssl_type' do shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-ssl@localhost'\"") do |r| expect(r.stdout).to match(/^ANY$/) expect(r.stderr).to be_empty end end end end context 'using user-w-x509@localhost with X509' do describe 'adding user' do it 'should work without errors' do pp = <<-EOS mysql_user { 'user-w-x509@localhost': password_hash => '*F9A8E96790775D196D12F53BCC88B8048FF62ED5', tls_options => ['X509'], } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the user' do shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| expect(r.stdout).to match(/^1$/) expect(r.stderr).to be_empty end end it 'should show correct ssl_type' do shell("mysql -NBe \"select SSL_TYPE from mysql.user where CONCAT(user, '@', host) = 'user-w-x509@localhost'\"") do |r| expect(r.stdout).to match(/^X509$/) expect(r.stderr).to be_empty end end end end end puppetlabs-mysql-3.10.0/spec/acceptance/types/mysql_grant_spec.rb0000644005276200011600000004340612763636535025117 0ustar jenkinsjenkinsrequire 'spec_helper_acceptance' require 'puppet' require 'puppet/util/package' require_relative '../mysql_helper.rb' describe 'mysql_grant' do before(:all) do pp = <<-EOS class { 'mysql::server': root_password => 'password', } EOS apply_manifest(pp, :catch_failures => true) end describe 'missing privileges for user' do it 'should fail' do pp = <<-EOS mysql_user { 'test1@tester': ensure => present, } mysql_grant { 'test1@tester/test.*': ensure => 'present', table => 'test.*', user => 'test1@tester', require => Mysql_user['test1@tester'], } EOS expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/privileges parameter is required/) end it 'should not find the user' do expect(shell("mysql -NBe \"SHOW GRANTS FOR test1@tester\"", { :acceptable_exit_codes => 1}).stderr).to match(/There is no such grant defined for user 'test1' on host 'tester'/) end end describe 'missing table for user' do it 'should fail' do pp = <<-EOS mysql_user { 'atest@tester': ensure => present, } mysql_grant { 'atest@tester/test.*': ensure => 'present', user => 'atest@tester', privileges => ['ALL'], require => Mysql_user['atest@tester'], } EOS apply_manifest(pp, :expect_failures => true) end it 'should not find the user' do expect(shell("mysql -NBe \"SHOW GRANTS FOR atest@tester\"", {:acceptable_exit_codes => 1}).stderr).to match(/There is no such grant defined for user 'atest' on host 'tester'/) end end describe 'adding privileges' do it 'should work without errors' do pp = <<-EOS mysql_user { 'test2@tester': ensure => present, } mysql_grant { 'test2@tester/test.*': ensure => 'present', table => 'test.*', user => 'test2@tester', privileges => ['SELECT', 'UPDATE'], require => Mysql_user['test2@tester'], } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the user' do shell("mysql -NBe \"SHOW GRANTS FOR test2@tester\"") do |r| expect(r.stdout).to match(/GRANT SELECT, UPDATE.*TO 'test2'@'tester'/) expect(r.stderr).to be_empty end end end describe 'adding privileges with special character in name' do it 'should work without errors' do pp = <<-EOS mysql_user { 'test-2@tester': ensure => present, } mysql_grant { 'test-2@tester/test.*': ensure => 'present', table => 'test.*', user => 'test-2@tester', privileges => ['SELECT', 'UPDATE'], require => Mysql_user['test-2@tester'], } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the user' do shell("mysql -NBe \"SHOW GRANTS FOR 'test-2'@tester\"") do |r| expect(r.stdout).to match(/GRANT SELECT, UPDATE.*TO 'test-2'@'tester'/) expect(r.stderr).to be_empty end end end describe 'adding privileges with invalid name' do it 'should fail' do pp = <<-EOS mysql_user { 'test2@tester': ensure => present, } mysql_grant { 'test': ensure => 'present', table => 'test.*', user => 'test2@tester', privileges => ['SELECT', 'UPDATE'], require => Mysql_user['test2@tester'], } EOS expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/name must match user and table parameters/) end end describe 'adding option' do it 'should work without errors' do pp = <<-EOS mysql_user { 'test3@tester': ensure => present, } mysql_grant { 'test3@tester/test.*': ensure => 'present', table => 'test.*', user => 'test3@tester', options => ['GRANT'], privileges => ['SELECT', 'UPDATE'], require => Mysql_user['test3@tester'], } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the user' do shell("mysql -NBe \"SHOW GRANTS FOR test3@tester\"") do |r| expect(r.stdout).to match(/GRANT SELECT, UPDATE ON `test`.* TO 'test3'@'tester' WITH GRANT OPTION$/) expect(r.stderr).to be_empty end end end describe 'adding all privileges without table' do it 'should fail' do pp = <<-EOS mysql_user { 'test4@tester': ensure => present, } mysql_grant { 'test4@tester/test.*': ensure => 'present', user => 'test4@tester', options => ['GRANT'], privileges => ['SELECT', 'UPDATE', 'ALL'], require => Mysql_user['test4@tester'], } EOS expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/table parameter is required./) end end describe 'adding all privileges' do it 'should only try to apply ALL' do pp = <<-EOS mysql_user { 'test4@tester': ensure => present, } mysql_grant { 'test4@tester/test.*': ensure => 'present', table => 'test.*', user => 'test4@tester', options => ['GRANT'], privileges => ['SELECT', 'UPDATE', 'ALL'], require => Mysql_user['test4@tester'], } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the user' do shell("mysql -NBe \"SHOW GRANTS FOR test4@tester\"") do |r| expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test4'@'tester' WITH GRANT OPTION/) expect(r.stderr).to be_empty end end end # Test combinations of user@host to ensure all cases work. describe 'short hostname' do it 'should apply' do pp = <<-EOS mysql_user { 'test@short': ensure => present, } mysql_grant { 'test@short/test.*': ensure => 'present', table => 'test.*', user => 'test@short', privileges => 'ALL', require => Mysql_user['test@short'], } mysql_user { 'test@long.hostname.com': ensure => present, } mysql_grant { 'test@long.hostname.com/test.*': ensure => 'present', table => 'test.*', user => 'test@long.hostname.com', privileges => 'ALL', require => Mysql_user['test@long.hostname.com'], } mysql_user { 'test@192.168.5.6': ensure => present, } mysql_grant { 'test@192.168.5.6/test.*': ensure => 'present', table => 'test.*', user => 'test@192.168.5.6', privileges => 'ALL', require => Mysql_user['test@192.168.5.6'], } mysql_user { 'test@2607:f0d0:1002:0051:0000:0000:0000:0004': ensure => present, } mysql_grant { 'test@2607:f0d0:1002:0051:0000:0000:0000:0004/test.*': ensure => 'present', table => 'test.*', user => 'test@2607:f0d0:1002:0051:0000:0000:0000:0004', privileges => 'ALL', require => Mysql_user['test@2607:f0d0:1002:0051:0000:0000:0000:0004'], } mysql_user { 'test@::1/128': ensure => present, } mysql_grant { 'test@::1/128/test.*': ensure => 'present', table => 'test.*', user => 'test@::1/128', privileges => 'ALL', require => Mysql_user['test@::1/128'], } EOS apply_manifest(pp, :catch_failures => true) end it 'finds short hostname' do shell("mysql -NBe \"SHOW GRANTS FOR test@short\"") do |r| expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'short'/) expect(r.stderr).to be_empty end end it 'finds long hostname' do shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'long.hostname.com'\"") do |r| expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'long.hostname.com'/) expect(r.stderr).to be_empty end end it 'finds ipv4' do shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.6'\"") do |r| expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'192.168.5.6'/) expect(r.stderr).to be_empty end end it 'finds ipv6' do shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'\"") do |r| expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'/) expect(r.stderr).to be_empty end end it 'finds short ipv6' do shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'::1/128'\"") do |r| expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'::1\/128'/) expect(r.stderr).to be_empty end end end describe 'complex test' do it 'setup mysql::server' do pp = <<-EOS $dbSubnet = '10.10.10.%' mysql_database { 'foo': ensure => present, } exec { 'mysql-create-table': command => '/usr/bin/mysql -NBe "CREATE TABLE foo.bar (name VARCHAR(20))"', environment => "HOME=${::root_home}", unless => '/usr/bin/mysql -NBe "SELECT 1 FROM foo.bar LIMIT 1;"', require => Mysql_database['foo'], } Mysql_grant { ensure => present, options => ['GRANT'], privileges => ['ALL'], table => '*.*', require => [ Mysql_database['foo'], Exec['mysql-create-table'] ], } mysql_user { "user1@${dbSubnet}": ensure => present, } mysql_grant { "user1@${dbSubnet}/*.*": user => "user1@${dbSubnet}", require => Mysql_user["user1@${dbSubnet}"], } mysql_user { "user2@${dbSubnet}": ensure => present, } mysql_grant { "user2@${dbSubnet}/foo.bar": privileges => ['SELECT', 'INSERT', 'UPDATE'], user => "user2@${dbSubnet}", table => 'foo.bar', require => Mysql_user["user2@${dbSubnet}"], } mysql_user { "user3@${dbSubnet}": ensure => present, } mysql_grant { "user3@${dbSubnet}/foo.*": privileges => ['SELECT', 'INSERT', 'UPDATE'], user => "user3@${dbSubnet}", table => 'foo.*', require => Mysql_user["user3@${dbSubnet}"], } mysql_user { 'web@%': ensure => present, } mysql_grant { 'web@%/*.*': user => 'web@%', require => Mysql_user['web@%'], } mysql_user { "web@${dbSubnet}": ensure => present, } mysql_grant { "web@${dbSubnet}/*.*": user => "web@${dbSubnet}", require => Mysql_user["web@${dbSubnet}"], } mysql_user { "web@${fqdn}": ensure => present, } mysql_grant { "web@${fqdn}/*.*": user => "web@${fqdn}", require => Mysql_user["web@${fqdn}"], } mysql_user { 'web@localhost': ensure => present, } mysql_grant { 'web@localhost/*.*': user => 'web@localhost', require => Mysql_user['web@localhost'], } EOS apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end end describe 'lower case privileges' do it 'create ALL privs' do pp = <<-EOS mysql_user { 'lowercase@localhost': ensure => present, } mysql_grant { 'lowercase@localhost/*.*': user => 'lowercase@localhost', privileges => 'ALL', table => '*.*', require => Mysql_user['lowercase@localhost'], } EOS apply_manifest(pp, :catch_failures => true) end it 'create lowercase all privs' do pp = <<-EOS mysql_user { 'lowercase@localhost': ensure => present, } mysql_grant { 'lowercase@localhost/*.*': user => 'lowercase@localhost', privileges => 'all', table => '*.*', require => Mysql_user['lowercase@localhost'], } EOS expect(apply_manifest(pp, :catch_failures => true).exit_code).to eq(0) end end describe 'adding procedure privileges' do it 'should work without errors' do pp = <<-EOS if $::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemmajrelease, '16.00') > 0 { exec { 'simpleproc-create': command => 'mysql --user="root" --password="password" --database=mysql --delimiter="//" -NBe "CREATE PROCEDURE simpleproc (OUT param1 INT) BEGIN SELECT COUNT(*) INTO param1 FROM t; end//"', path => '/usr/bin/', before => Mysql_user['test2@tester'], } } mysql_user { 'test2@tester': ensure => present, } mysql_grant { 'test2@tester/PROCEDURE mysql.simpleproc': ensure => 'present', table => 'PROCEDURE mysql.simpleproc', user => 'test2@tester', privileges => ['EXECUTE'], require => Mysql_user['test2@tester'], } EOS apply_manifest(pp, :catch_failures => true) end it 'should find the user' do shell("mysql -NBe \"SHOW GRANTS FOR test2@tester\"") do |r| expect(r.stdout).to match(/GRANT EXECUTE ON PROCEDURE `mysql`.`simpleproc` TO 'test2'@'tester'/) expect(r.stderr).to be_empty end end end describe 'grants with skip-name-resolve specified' do it 'setup mysql::server' do pp = <<-EOS class { 'mysql::server': override_options => { 'mysqld' => {'skip-name-resolve' => true} }, restart => true, } EOS apply_manifest(pp, :catch_failures => true) end it 'should apply' do pp = <<-EOS mysql_user { 'test@fqdn.com': ensure => present, } mysql_grant { 'test@fqdn.com/test.*': ensure => 'present', table => 'test.*', user => 'test@fqdn.com', privileges => 'ALL', require => Mysql_user['test@fqdn.com'], } mysql_user { 'test@192.168.5.7': ensure => present, } mysql_grant { 'test@192.168.5.7/test.*': ensure => 'present', table => 'test.*', user => 'test@192.168.5.7', privileges => 'ALL', require => Mysql_user['test@192.168.5.7'], } EOS apply_manifest(pp, :catch_failures => true) end it 'should fail with fqdn' do pre_run if ! version_is_greater_than('5.7.0') expect(shell("mysql -NBe \"SHOW GRANTS FOR test@fqdn.com\"", { :acceptable_exit_codes => 1}).stderr).to match(/There is no such grant defined for user 'test' on host 'fqdn.com'/) end end it 'finds ipv4' do shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.7'\"") do |r| expect(r.stdout).to match(/GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'192.168.5.7'/) expect(r.stderr).to be_empty end end it 'should fail to execute while applying' do pp = <<-EOS mysql_user { 'test@fqdn.com': ensure => present, } mysql_grant { 'test@fqdn.com/test.*': ensure => 'present', table => 'test.*', user => 'test@fqdn.com', privileges => 'ALL', require => Mysql_user['test@fqdn.com'], } EOS mysql_cmd = shell('which mysql').stdout.chomp shell("mv #{mysql_cmd} #{mysql_cmd}.bak") expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Command mysql is missing/) shell("mv #{mysql_cmd}.bak #{mysql_cmd}") end it 'reset mysql::server config' do pp = <<-EOS class { 'mysql::server': restart => true, } EOS apply_manifest(pp, :catch_failures => true) end end describe 'adding privileges to specific table' do # Using puppet_apply as a helper it 'setup mysql server' do pp = <<-EOS class { 'mysql::server': override_options => { 'root_password' => 'password' } } EOS apply_manifest(pp, :catch_failures => true) end it 'creates grant on missing table will fail' do pp = <<-EOS mysql_user { 'test@localhost': ensure => present, } mysql_grant { 'test@localhost/grant_spec_db.grant_spec_table': user => 'test@localhost', privileges => ['SELECT'], table => 'grant_spec_db.grant_spec_table', require => Mysql_user['test@localhost'], } EOS expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/Table 'grant_spec_db\.grant_spec_table' doesn't exist/) end it 'creates table' do pp = <<-EOS file { '/tmp/grant_spec_table.sql': ensure => file, content => 'CREATE TABLE grant_spec_table (id int);', before => Mysql::Db['grant_spec_db'], } mysql::db { 'grant_spec_db': user => 'root1', password => 'password', sql => '/tmp/grant_spec_table.sql', } EOS apply_manifest(pp, :catch_failures => true) end it 'should have the table' do expect(shell("mysql -e 'show tables;' grant_spec_db|grep grant_spec_table").exit_code).to be_zero end end end puppetlabs-mysql-3.10.0/spec/acceptance/mysql_helper.rb0000644005276200011600000000051512763636535023077 0ustar jenkinsjenkins def pre_run apply_manifest("class { 'mysql::server': root_password => 'password' }", :catch_failures => true) @mysql_version = (on default, 'mysql --version').output.chomp.match(/\d+\.\d+\.\d+/)[0] end def version_is_greater_than(version) return Puppet::Util::Package.versioncmp(@mysql_version, version) > 0 end puppetlabs-mysql-3.10.0/spec/acceptance/mysql_backup_spec.rb0000644005276200011600000001430412763636535024100 0ustar jenkinsjenkinsrequire 'spec_helper_acceptance' require 'puppet' require 'puppet/util/package' require_relative './mysql_helper.rb' describe 'mysql::server::backup class' do context 'should work with no errors' do it 'when configuring mysql backups' do pp = <<-EOS class { 'mysql::server': root_password => 'password' } mysql::db { [ 'backup1', 'backup2' ]: user => 'backup', password => 'secret', } class { 'mysql::server::backup': backupuser => 'myuser', backuppassword => 'mypassword', backupdir => '/tmp/backups', backupcompress => true, postscript => [ 'rm -rf /var/tmp/mysqlbackups', 'rm -f /var/tmp/mysqlbackups.done', 'cp -r /tmp/backups /var/tmp/mysqlbackups', 'touch /var/tmp/mysqlbackups.done', ], execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin', } EOS apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_failures => true) end end describe 'mysqlbackup.sh' do it 'should run mysqlbackup.sh with no errors' do pre_run if ! version_is_greater_than('5.7.0') shell("/usr/local/sbin/mysqlbackup.sh") do |r| expect(r.stderr).to eq("") end end end it 'should dump all databases to single file' do pre_run if ! version_is_greater_than('5.7.0') shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r| expect(r.stdout).to match(/1/) expect(r.exit_code).to be_zero end end end context 'should create one file per database per run' do it 'executes mysqlbackup.sh a second time' do pre_run if ! version_is_greater_than('5.7.0') shell('sleep 1') shell('/usr/local/sbin/mysqlbackup.sh') end end it 'creates at least one backup tarball' do pre_run if ! version_is_greater_than('5.7.0') shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r| expect(r.stdout).to match(/2/) expect(r.exit_code).to be_zero end end end end end context 'with one file per database' do context 'should work with no errors' do it 'when configuring mysql backups' do pp = <<-EOS class { 'mysql::server': root_password => 'password' } mysql::db { [ 'backup1', 'backup2' ]: user => 'backup', password => 'secret', } class { 'mysql::server::backup': backupuser => 'myuser', backuppassword => 'mypassword', backupdir => '/tmp/backups', backupcompress => true, file_per_database => true, postscript => [ 'rm -rf /var/tmp/mysqlbackups', 'rm -f /var/tmp/mysqlbackups.done', 'cp -r /tmp/backups /var/tmp/mysqlbackups', 'touch /var/tmp/mysqlbackups.done', ], execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin', } EOS apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_failures => true) end end describe 'mysqlbackup.sh' do it 'should run mysqlbackup.sh with no errors without root credentials' do pre_run if ! version_is_greater_than('5.7.0') shell("HOME=/tmp/dontreadrootcredentials /usr/local/sbin/mysqlbackup.sh") do |r| expect(r.stderr).to eq("") end end end it 'should create one file per database' do pre_run if ! version_is_greater_than('5.7.0') ['backup1', 'backup2'].each do |database| shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| expect(r.stdout).to match(/1/) expect(r.exit_code).to be_zero end end end end context 'should create one file per database per run' do it 'executes mysqlbackup.sh a second time' do pre_run if ! version_is_greater_than('5.7.0') shell('sleep 1') shell('HOME=/tmp/dontreadrootcredentials /usr/local/sbin/mysqlbackup.sh') end end it 'has one file per database per run' do pre_run if ! version_is_greater_than('5.7.0') ['backup1', 'backup2'].each do |database| shell("ls -l /tmp/backups/mysql_backup_#{database}_*-*.sql.bz2 | wc -l") do |r| expect(r.stdout).to match(/2/) expect(r.exit_code).to be_zero end end end end end end end context 'with triggers and routines' do it 'when configuring mysql backups with triggers and routines' do pre_run pp = <<-EOS class { 'mysql::server': root_password => 'password' } mysql::db { [ 'backup1', 'backup2' ]: user => 'backup', password => 'secret', } package { 'bzip2': ensure => present, } class { 'mysql::server::backup': backupuser => 'myuser', backuppassword => 'mypassword', backupdir => '/tmp/backups', backupcompress => true, file_per_database => true, include_triggers => #{version_is_greater_than('5.1.5')}, include_routines => true, postscript => [ 'rm -rf /var/tmp/mysqlbackups', 'rm -f /var/tmp/mysqlbackups.done', 'cp -r /tmp/backups /var/tmp/mysqlbackups', 'touch /var/tmp/mysqlbackups.done', ], execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin', require => Package['bzip2'], } EOS apply_manifest(pp, :catch_failures => true) end it 'should run mysqlbackup.sh with no errors' do pre_run if ! version_is_greater_than('5.7.0') shell("/usr/local/sbin/mysqlbackup.sh") do |r| expect(r.stderr).to eq("") end end end end end puppetlabs-mysql-3.10.0/spec/acceptance/mysql_db_spec.rb0000644005276200011600000000345712746170223023213 0ustar jenkinsjenkinsrequire 'spec_helper_acceptance' describe 'mysql::db define' do describe 'creating a database' do let(:pp) do <<-EOS class { 'mysql::server': root_password => 'password' } mysql::db { 'spec1': user => 'root1', password => 'password', } EOS end it_behaves_like "a idempotent resource" describe command("mysql -e 'show databases;'") do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to match /^spec1$/ } end end describe 'creating a database with post-sql' do let(:pp) do <<-EOS class { 'mysql::server': override_options => { 'root_password' => 'password' } } file { '/tmp/spec.sql': ensure => file, content => 'CREATE TABLE table1 (id int);', before => Mysql::Db['spec2'], } mysql::db { 'spec2': user => 'root1', password => 'password', sql => '/tmp/spec.sql', } EOS end it_behaves_like "a idempotent resource" describe command("mysql -e 'show tables;' spec2") do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to match /^table1$/ } end end describe 'creating a database with dbname parameter' do let(:check_command) { " | grep realdb" } let(:pp) do <<-EOS class { 'mysql::server': override_options => { 'root_password' => 'password' } } mysql::db { 'spec1': user => 'root1', password => 'password', dbname => 'realdb', } EOS end it_behaves_like "a idempotent resource" describe command("mysql -e 'show databases;'") do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to match /^realdb$/ } end end end puppetlabs-mysql-3.10.0/spec/acceptance/nodesets/0000755005276200011600000000000013010160602021636 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/acceptance/nodesets/docker/0000755005276200011600000000000013010160602023105 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/acceptance/nodesets/docker/debian-8.yml0000644005276200011600000000054412746170223025241 0ustar jenkinsjenkinsHOSTS: debian-8-x64: platform: debian-8-amd64 hypervisor: docker image: debian:8 docker_preserve_image: true docker_cmd: '["/sbin/init"]' docker_image_commands: - 'apt-get update && apt-get install -y net-tools wget locales strace lsof && echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen' CONFIG: trace_limit: 200 puppetlabs-mysql-3.10.0/spec/acceptance/nodesets/docker/centos-7.yml0000644005276200011600000000057512746170223025315 0ustar jenkinsjenkinsHOSTS: centos-7-x64: platform: el-7-x86_64 hypervisor: docker image: centos:7 docker_preserve_image: true docker_cmd: '["/usr/sbin/init"]' # install various tools required to get the image up to usable levels docker_image_commands: - 'yum install -y crontabs tar wget openssl sysvinit-tools iproute which initscripts' CONFIG: trace_limit: 200 puppetlabs-mysql-3.10.0/spec/acceptance/nodesets/docker/ubuntu-14.04.yml0000644005276200011600000000073212746170223025637 0ustar jenkinsjenkinsHOSTS: ubuntu-1404-x64: platform: ubuntu-14.04-amd64 hypervisor: docker image: ubuntu:14.04 docker_preserve_image: true docker_cmd: '["/sbin/init"]' docker_image_commands: # ensure that upstart is booting correctly in the container - 'rm /usr/sbin/policy-rc.d && rm /sbin/initctl && dpkg-divert --rename --remove /sbin/initctl && apt-get update && apt-get install -y net-tools wget && locale-gen en_US.UTF-8' CONFIG: trace_limit: 200 puppetlabs-mysql-3.10.0/spec/acceptance/nodesets/debian-8-x64.yml0000644005276200011600000000026112746170223024405 0ustar jenkinsjenkinsHOSTS: debian-8-x64: roles: - agent - default platform: debian-8-amd64 hypervisor: vagrant box: puppetlabs/debian-8.2-64-nocm CONFIG: type: foss puppetlabs-mysql-3.10.0/spec/acceptance/nodesets/centos-7-x64.yml0000644005276200011600000000025612763636535024475 0ustar jenkinsjenkinsHOSTS: centos-7-x64: roles: - agent - default platform: el-7-x86_64 hypervisor: vagrant box: puppetlabs/centos-7.2-64-nocm CONFIG: type: foss puppetlabs-mysql-3.10.0/spec/acceptance/nodesets/default.yml0000644005276200011600000000027212746170223024025 0ustar jenkinsjenkinsHOSTS: ubuntu-1404-x64: roles: - agent - default platform: ubuntu-14.04-amd64 hypervisor: vagrant box: puppetlabs/ubuntu-14.04-64-nocm CONFIG: type: foss puppetlabs-mysql-3.10.0/spec/spec_helper_local.rb0000644005276200011600000000006712746170223021736 0ustar jenkinsjenkinsrequire 'rspec-puppet-facts' include RspecPuppetFacts puppetlabs-mysql-3.10.0/spec/unit/0000755005276200011600000000000013010160602016703 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/unit/facter/0000755005276200011600000000000013010160602020147 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/unit/facter/mysql_server_id_spec.rb0000644005276200011600000000113612763636535024751 0ustar jenkinsjenkinsrequire "spec_helper" describe Facter::Util::Fact do before { Facter.clear } describe "mysql_server_id" do context "igalic's laptop" do before :each do Facter.fact(:macaddress).stubs(:value).returns('3c:97:0e:69:fb:e1') end it do Facter.fact(:mysql_server_id).value.to_s.should == '4116385' end end context "node with lo only" do before :each do Facter.fact(:macaddress).stubs(:value).returns('00:00:00:00:00:00') end it do Facter.fact(:mysql_server_id).value.to_s.should == '0' end end end end puppetlabs-mysql-3.10.0/spec/unit/facter/mysql_version_spec.rb0000644005276200011600000000067512746170223024447 0ustar jenkinsjenkinsrequire "spec_helper" describe Facter::Util::Fact do before { Facter.clear } describe "mysql_version" do context 'with value' do before :each do Facter::Util::Resolution.stubs(:exec).with('mysql --version').returns('mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1') end it { expect(Facter.fact(:mysql_version).value).to eq('5.0.95') } end end end puppetlabs-mysql-3.10.0/spec/unit/facter/mysqld_version_spec.rb0000644005276200011600000000106213010160217024565 0ustar jenkinsjenkinsrequire "spec_helper" describe Facter::Util::Fact do before { Facter.clear } describe "mysqld_version" do context 'with value' do before :each do Facter::Util::Resolution.stubs(:exec).with('mysqld -V 2>/dev/null').returns('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)') end it { expect(Facter.fact(:mysqld_version).value).to eq('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)') } end end end puppetlabs-mysql-3.10.0/spec/unit/puppet/0000755005276200011600000000000013010160602020220 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/unit/puppet/type/0000755005276200011600000000000013010160602021201 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/unit/puppet/type/mysql_plugin_spec.rb0000644005276200011600000000112512746170223025301 0ustar jenkinsjenkinsrequire 'puppet' require 'puppet/type/mysql_plugin' describe Puppet::Type.type(:mysql_plugin) do before :each do @plugin = Puppet::Type.type(:mysql_plugin).new(:name => 'test', :soname => 'test.so') end it 'should accept a plugin name' do expect(@plugin[:name]).to eq('test') end it 'should accept a library name' do @plugin[:soname] = 'test.so' expect(@plugin[:soname]).to eq('test.so') end it 'should require a name' do expect { Puppet::Type.type(:mysql_plugin).new({}) }.to raise_error(Puppet::Error, 'Title or name must be provided') end end puppetlabs-mysql-3.10.0/spec/unit/puppet/type/mysql_database_spec.rb0000644005276200011600000000136612746170223025556 0ustar jenkinsjenkinsrequire 'puppet' require 'puppet/type/mysql_database' describe Puppet::Type.type(:mysql_database) do before :each do @user = Puppet::Type.type(:mysql_database).new(:name => 'test', :charset => 'utf8', :collate => 'utf8_blah_ci') end it 'should accept a database name' do expect(@user[:name]).to eq('test') end it 'should accept a charset' do @user[:charset] = 'latin1' expect(@user[:charset]).to eq('latin1') end it 'should accept a collate' do @user[:collate] = 'latin1_swedish_ci' expect(@user[:collate]).to eq('latin1_swedish_ci') end it 'should require a name' do expect { Puppet::Type.type(:mysql_database).new({}) }.to raise_error(Puppet::Error, 'Title or name must be provided') end end puppetlabs-mysql-3.10.0/spec/unit/puppet/type/mysql_user_spec.rb0000644005276200011600000001037612763636535025005 0ustar jenkinsjenkinsrequire 'puppet' require 'puppet/type/mysql_user' describe Puppet::Type.type(:mysql_user) do context "On MySQL 5.x" do before :each do Facter.stubs(:value).with(:mysql_version).returns("5.6.24") end it 'should fail with a long user name' do expect { Puppet::Type.type(:mysql_user).new({:name => '12345678901234567@localhost', :password_hash => 'pass'}) }.to raise_error /MySQL usernames are limited to a maximum of 16 characters/ end end context "On MariaDB 10.0.0+" do before :each do Facter.stubs(:value).with(:mysql_version).returns("10.0.19") @user = Puppet::Type.type(:mysql_user).new(:name => '12345678901234567@localhost', :password_hash => 'pass') end it 'should succeed with a long user name on MariaDB' do expect(@user[:name]).to eq('12345678901234567@localhost') end end it 'should require a name' do expect { Puppet::Type.type(:mysql_user).new({}) }.to raise_error(Puppet::Error, 'Title or name must be provided') end context 'using foo@localhost' do before :each do @user = Puppet::Type.type(:mysql_user).new(:name => 'foo@localhost', :password_hash => 'pass') end it 'should accept a user name' do expect(@user[:name]).to eq('foo@localhost') end it 'should accept a password' do @user[:password_hash] = 'foo' expect(@user[:password_hash]).to eq('foo') end end context 'using foo@LocalHost' do before :each do @user = Puppet::Type.type(:mysql_user).new(:name => 'foo@LocalHost', :password_hash => 'pass') end it 'should lowercase the user name' do expect(@user[:name]).to eq('foo@localhost') end end context 'using foo@192.168.1.0/255.255.255.0' do before :each do @user = Puppet::Type.type(:mysql_user).new(:name => 'foo@192.168.1.0/255.255.255.0', :password_hash => 'pass') end it 'should create the user with the netmask' do expect(@user[:name]).to eq('foo@192.168.1.0/255.255.255.0') end end context 'using allo_wed$char@localhost' do before :each do @user = Puppet::Type.type(:mysql_user).new(:name => 'allo_wed$char@localhost', :password_hash => 'pass') end it 'should accept a user name' do expect(@user[:name]).to eq('allo_wed$char@localhost') end end context 'ensure the default \'debian-sys-main\'@localhost user can be parsed' do before :each do @user = Puppet::Type.type(:mysql_user).new(:name => '\'debian-sys-maint\'@localhost', :password_hash => 'pass') end it 'should accept a user name' do expect(@user[:name]).to eq('\'debian-sys-maint\'@localhost') end end context 'using a quoted 16 char username' do before :each do @user = Puppet::Type.type(:mysql_user).new(:name => '"debian-sys-maint"@localhost', :password_hash => 'pass') end it 'should accept a user name' do expect(@user[:name]).to eq('"debian-sys-maint"@localhost') end end context 'using a quoted username that is too long ' do before :each do Facter.stubs(:value).with(:mysql_version).returns("5.6.24") end it 'should fail with a size error' do expect { Puppet::Type.type(:mysql_user).new(:name => '"debian-sys-maint2"@localhost', :password_hash => 'pass') }.to raise_error /MySQL usernames are limited to a maximum of 16 characters/ end end context 'using `speci!al#`@localhost' do before :each do @user = Puppet::Type.type(:mysql_user).new(:name => '`speci!al#`@localhost', :password_hash => 'pass') end it 'should accept a quoted user name with special chatracters' do expect(@user[:name]).to eq('`speci!al#`@localhost') end end context 'using in-valid@localhost' do before :each do @user = Puppet::Type.type(:mysql_user).new(:name => 'in-valid@localhost', :password_hash => 'pass') end it 'should accept a user name with special chatracters' do expect(@user[:name]).to eq('in-valid@localhost') end end context 'using "misquoted@localhost' do it 'should fail with a misquoted username is used' do expect { Puppet::Type.type(:mysql_user).new(:name => '"misquoted@localhost', :password_hash => 'pass') }.to raise_error /Invalid database user "misquoted@localhost/ end end end puppetlabs-mysql-3.10.0/spec/unit/puppet/type/mysql_grant_spec.rb0000644005276200011600000000447012746170223025124 0ustar jenkinsjenkinsrequire 'puppet' require 'puppet/type/mysql_grant' describe Puppet::Type.type(:mysql_grant) do before :each do @user = Puppet::Type.type(:mysql_grant).new(:name => 'foo@localhost/*.*', :privileges => ['ALL', 'PROXY'], :table => ['*.*','@'], :user => 'foo@localhost') end it 'should accept a grant name' do expect(@user[:name]).to eq('foo@localhost/*.*') end it 'should accept ALL privileges' do @user[:privileges] = 'ALL' expect(@user[:privileges]).to eq(['ALL']) end it 'should accept PROXY privilege' do @user[:privileges] = 'PROXY' expect(@user[:privileges]).to eq(['PROXY']) end it 'should accept a table' do @user[:table] = '*.*' expect(@user[:table]).to eq('*.*') end it 'should accept @ for table' do @user[:table] = '@' expect(@user[:table]).to eq('@') end it 'should accept a user' do @user[:user] = 'foo@localhost' expect(@user[:user]).to eq('foo@localhost') end it 'should require a name' do expect { Puppet::Type.type(:mysql_grant).new({}) }.to raise_error(Puppet::Error, 'Title or name must be provided') end it 'should require the name to match the user and table' do expect { Puppet::Type.type(:mysql_grant).new(:name => 'foo', :privileges => ['ALL', 'PROXY'], :table => ['*.*','@'], :user => 'foo@localhost') }.to raise_error /name must match user and table parameters/ end describe 'it should munge privileges' do it 'to just ALL' do @user = Puppet::Type.type(:mysql_grant).new( :name => 'foo@localhost/*.*', :table => ['*.*','@'], :user => 'foo@localhost', :privileges => ['ALL', 'PROXY'] ) expect(@user[:privileges]).to eq(['ALL']) end it 'to upcase and ordered' do @user = Puppet::Type.type(:mysql_grant).new( :name => 'foo@localhost/*.*', :table => ['*.*','@'], :user => 'foo@localhost', :privileges => ['select', 'Insert'] ) expect(@user[:privileges]).to eq(['INSERT', 'SELECT']) end it 'ordered including column privileges' do @user = Puppet::Type.type(:mysql_grant).new( :name => 'foo@localhost/*.*', :table => ['*.*','@'], :user => 'foo@localhost', :privileges => ['SELECT(Host,Address)', 'Insert'] ) expect(@user[:privileges]).to eq(['INSERT', 'SELECT (Address, Host)']) end end end puppetlabs-mysql-3.10.0/spec/unit/puppet/functions/0000755005276200011600000000000013010160602022230 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/unit/puppet/functions/mysql_password_spec.rb0000644005276200011600000000231112746170223026672 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'the mysql_password function' do before :all do Puppet::Parser::Functions.autoloader.loadall end let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it 'should exist' do expect(Puppet::Parser::Functions.function('mysql_password')).to eq('function_mysql_password') end it 'should raise a ParseError if there is less than 1 arguments' do expect { scope.function_mysql_password([]) }.to( raise_error(Puppet::ParseError)) end it 'should raise a ParseError if there is more than 1 arguments' do expect { scope.function_mysql_password(%w(foo bar)) }.to( raise_error(Puppet::ParseError)) end it 'should convert password into a hash' do result = scope.function_mysql_password(%w(password)) expect(result).to(eq('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19')) end it 'should convert an empty password into a empty string' do result = scope.function_mysql_password([""]) expect(result).to(eq('')) end it 'should not convert a password that is already a hash' do result = scope.function_mysql_password(['*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19']) expect(result).to(eq('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19')) end end puppetlabs-mysql-3.10.0/spec/unit/puppet/functions/mysql_deepmerge_spec.rb0000644005276200011600000000742612746170223027001 0ustar jenkinsjenkins#! /usr/bin/env ruby -S rspec require 'spec_helper' describe Puppet::Parser::Functions.function(:mysql_deepmerge) do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } describe 'when calling mysql_deepmerge from puppet' do it "should not compile when no arguments are passed" do skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = '$x = mysql_deepmerge()' expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /wrong number of arguments/) end it "should not compile when 1 argument is passed" do skip("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ Puppet[:code] = "$my_hash={'one' => 1}\n$x = mysql_deepmerge($my_hash)" expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /wrong number of arguments/) end end describe 'when calling mysql_deepmerge on the scope instance' do it 'should require all parameters are hashes' do expect { new_hash = scope.function_mysql_deepmerge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/) expect { new_hash = scope.function_mysql_deepmerge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) end it 'should accept empty strings as puppet undef' do expect { new_hash = scope.function_mysql_deepmerge([{}, ''])}.not_to raise_error end it 'should be able to mysql_deepmerge two hashes' do new_hash = scope.function_mysql_deepmerge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}]) expect(new_hash['one']).to eq('1') expect(new_hash['two']).to eq('2') expect(new_hash['three']).to eq('2') end it 'should mysql_deepmerge multiple hashes' do hash = scope.function_mysql_deepmerge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) expect(hash['one']).to eq('3') end it 'should accept empty hashes' do expect(scope.function_mysql_deepmerge([{},{},{}])).to eq({}) end it 'should mysql_deepmerge subhashes' do hash = scope.function_mysql_deepmerge([{'one' => 1}, {'two' => 2, 'three' => { 'four' => 4 } }]) expect(hash['one']).to eq(1) expect(hash['two']).to eq(2) expect(hash['three']).to eq({ 'four' => 4 }) end it 'should append to subhashes' do hash = scope.function_mysql_deepmerge([{'one' => { 'two' => 2 } }, { 'one' => { 'three' => 3 } }]) expect(hash['one']).to eq({ 'two' => 2, 'three' => 3 }) end it 'should append to subhashes 2' do hash = scope.function_mysql_deepmerge([{'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, {'two' => 'dos', 'three' => { 'five' => 5 } }]) expect(hash['one']).to eq(1) expect(hash['two']).to eq('dos') expect(hash['three']).to eq({ 'four' => 4, 'five' => 5 }) end it 'should append to subhashes 3' do hash = scope.function_mysql_deepmerge([{ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } }]) expect(hash['key1']).to eq({ 'a' => 1, 'b' => 99 }) expect(hash['key2']).to eq({ 'c' => 3 }) end it 'should equate keys mod dash and underscore' do hash = scope.function_mysql_deepmerge([{ 'a-b-c' => 1 } , { 'a_b_c' => 10 }]) expect(hash['a_b_c']).to eq(10) expect(hash).not_to have_key('a-b-c') end it 'should keep style of the last when keys are euqal mod dash and underscore' do hash = scope.function_mysql_deepmerge([{ 'a-b-c' => 1, 'b_c_d' => { 'c-d-e' => 2, 'e-f-g' => 3 }} , { 'a_b_c' => 10, 'b-c-d' => { 'c_d_e' => 12 } }]) expect(hash['a_b_c']).to eq(10) expect(hash).not_to have_key('a-b-c') expect(hash['b-c-d']).to eq({ 'e-f-g' => 3, 'c_d_e' => 12 }) expect(hash).not_to have_key('b_c_d') end end end puppetlabs-mysql-3.10.0/spec/unit/puppet/provider/0000755005276200011600000000000013010160602022052 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/unit/puppet/provider/mysql_database/0000755005276200011600000000000013010160602025043 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/unit/puppet/provider/mysql_database/mysql_spec.rb0000644005276200011600000000731212746170223027571 0ustar jenkinsjenkinsrequire 'spec_helper' describe Puppet::Type.type(:mysql_database).provider(:mysql) do let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' } let(:raw_databases) do <<-SQL_OUTPUT information_schema mydb mysql performance_schema test SQL_OUTPUT end let(:parsed_databases) { %w(information_schema mydb mysql performance_schema test) } let(:resource) { Puppet::Type.type(:mysql_database).new( { :ensure => :present, :charset => 'latin1', :collate => 'latin1_swedish_ci', :name => 'new_database', :provider => described_class.name } )} let(:provider) { resource.provider } before :each do Facter.stubs(:value).with(:root_home).returns('/root') Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql') File.stubs(:file?).with('/root/.my.cnf').returns(true) provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns('new_database') provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", 'new_database']).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") end let(:instance) { provider.class.instances.first } describe 'self.instances' do it 'returns an array of databases' do provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns(raw_databases) raw_databases.each_line do |db| provider.class.stubs(:mysql).with([defaults_file, '-NBe', "show variables like '%_database'", db.chomp]).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") end databases = provider.class.instances.collect {|x| x.name } expect(parsed_databases).to match_array(databases) end end describe 'self.prefetch' do it 'exists' do provider.class.instances provider.class.prefetch({}) end end describe 'create' do it 'makes a database' do provider.expects(:mysql).with([defaults_file, '-NBe', "create database if not exists `#{resource[:name]}` character set `#{resource[:charset]}` collate `#{resource[:collate]}`"]) provider.expects(:exists?).returns(true) expect(provider.create).to be_truthy end end describe 'destroy' do it 'removes a database if present' do provider.expects(:mysql).with([defaults_file, '-NBe', "drop database if exists `#{resource[:name]}`"]) provider.expects(:exists?).returns(false) expect(provider.destroy).to be_truthy end end describe 'exists?' do it 'checks if database exists' do expect(instance.exists?).to be_truthy end end describe 'self.defaults_file' do it 'sets --defaults-extra-file' do File.stubs(:file?).with('/root/.my.cnf').returns(true) expect(provider.defaults_file).to eq '--defaults-extra-file=/root/.my.cnf' end it 'fails if file missing' do File.stubs(:file?).with('/root/.my.cnf').returns(false) expect(provider.defaults_file).to be_nil end end describe 'charset' do it 'returns a charset' do expect(instance.charset).to eq('latin1') end end describe 'charset=' do it 'changes the charset' do provider.expects(:mysql).with([defaults_file, '-NBe', "alter database `#{resource[:name]}` CHARACTER SET blah"]).returns('0') provider.charset=('blah') end end describe 'collate' do it 'returns a collate' do expect(instance.collate).to eq('latin1_swedish_ci') end end describe 'collate=' do it 'changes the collate' do provider.expects(:mysql).with([defaults_file, '-NBe', "alter database `#{resource[:name]}` COLLATE blah"]).returns('0') provider.collate=('blah') end end end puppetlabs-mysql-3.10.0/spec/unit/puppet/provider/mysql_plugin/0000755005276200011600000000000013010160602024575 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/unit/puppet/provider/mysql_plugin/mysql_spec.rb0000644005276200011600000000410612746170223027321 0ustar jenkinsjenkinsrequire 'spec_helper' describe Puppet::Type.type(:mysql_plugin).provider(:mysql) do let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' } let(:resource) { Puppet::Type.type(:mysql_plugin).new( { :ensure => :present, :soname => 'auth_socket.so', :name => 'auth_socket', :provider => described_class.name } )} let(:provider) { resource.provider } before :each do Facter.stubs(:value).with(:root_home).returns('/root') Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql') File.stubs(:file?).with('/root/.my.cnf').returns(true) provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show plugins']).returns('auth_socket ACTIVE AUTHENTICATION auth_socket.so GPL') end let(:instance) { provider.class.instances.first } describe 'self.prefetch' do it 'exists' do provider.class.instances provider.class.prefetch({}) end end describe 'create' do it 'loads a plugin' do provider.expects(:mysql).with([defaults_file, '-NBe', "install plugin #{resource[:name]} soname '#{resource[:soname]}'"]) provider.expects(:exists?).returns(true) expect(provider.create).to be_truthy end end describe 'destroy' do it 'unloads a plugin if present' do provider.expects(:mysql).with([defaults_file, '-NBe', "uninstall plugin #{resource[:name]}"]) provider.expects(:exists?).returns(false) expect(provider.destroy).to be_truthy end end describe 'exists?' do it 'checks if plugin exists' do expect(instance.exists?).to be_truthy end end describe 'self.defaults_file' do it 'sets --defaults-extra-file' do File.stubs(:file?).with('/root/.my.cnf').returns(true) expect(provider.defaults_file).to eq '--defaults-extra-file=/root/.my.cnf' end it 'fails if file missing' do File.stubs(:file?).with('/root/.my.cnf').returns(false) expect(provider.defaults_file).to be_nil end end describe 'soname' do it 'returns a soname' do expect(instance.soname).to eq('auth_socket.so') end end end puppetlabs-mysql-3.10.0/spec/unit/puppet/provider/mysql_user/0000755005276200011600000000000013010160602024255 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/unit/puppet/provider/mysql_user/mysql_spec.rb0000644005276200011600000004316113010160217026770 0ustar jenkinsjenkinsrequire 'spec_helper' describe Puppet::Type.type(:mysql_user).provider(:mysql) do # Output of mysqld -V mysql_version_string_hash = { 'mysql-5.5' => { :version => '5.5.46', :string => '/usr/sbin/mysqld Ver 5.5.46-log for Linux on x86_64 (MySQL Community Server (GPL))', :mysql_type => 'mysql', }, 'mysql-5.6' => { :version => '5.6.27', :string => '/usr/sbin/mysqld Ver 5.6.27 for Linux on x86_64 (MySQL Community Server (GPL))', :mysql_type => 'mysql', }, 'mysql-5.7.1' => { :version => '5.7.1', :string => '/usr/sbin/mysqld Ver 5.7.1 for Linux on x86_64 (MySQL Community Server (GPL))', :mysql_type => 'mysql', }, 'mysql-5.7.6' => { :version => '5.7.8', :string => '/usr/sbin/mysqld Ver 5.7.8-rc for Linux on x86_64 (MySQL Community Server (GPL))', :mysql_type => 'mysql', }, 'mariadb-10.0' => { :version => '10.0.21', :string => '/usr/sbin/mysqld Ver 10.0.21-MariaDB for Linux on x86_64 (MariaDB Server)', :mysql_type => 'mariadb', }, 'mariadb-10.0-deb8' => { :version => '10.0.23', :string => '/usr/sbin/mysqld (mysqld 10.0.23-MariaDB-0+deb8u1)', :mysql_type => 'mariadb', }, 'percona-5.5' => { :version => '5.5.39', :string => 'mysqld Ver 5.5.39-36.0-55 for Linux on x86_64 (Percona XtraDB Cluster (GPL), Release rel36.0, Revision 824, WSREP version 25.11, wsrep_25.11.r4023)', :mysql_type => 'percona', }, } let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' } let(:system_database) { '--database=mysql' } let(:newhash) { '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5' } let(:raw_users) do <<-SQL_OUTPUT root@127.0.0.1 root@::1 @localhost debian-sys-maint@localhost root@localhost usvn_user@localhost @vagrant-ubuntu-raring-64 SQL_OUTPUT end let(:parsed_users) { %w(root@127.0.0.1 root@::1 @localhost debian-sys-maint@localhost root@localhost usvn_user@localhost @vagrant-ubuntu-raring-64) } let(:resource) { Puppet::Type.type(:mysql_user).new( { :ensure => :present, :password_hash => '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4', :name => 'joe@localhost', :max_user_connections => '10', :max_connections_per_hour => '10', :max_queries_per_hour => '10', :max_updates_per_hour => '10', :provider => described_class.name } )} let(:provider) { resource.provider } before :each do # Set up the stubs for an instances call. Facter.stubs(:value).with(:root_home).returns('/root') Facter.stubs(:value).with(:mysql_version).returns('5.6.24') provider.class.instance_variable_set(:@mysqld_version_string, '5.6.24') Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql') Puppet::Util.stubs(:which).with('mysqld').returns('/usr/sbin/mysqld') File.stubs(:file?).with('/root/.my.cnf').returns(true) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns('joe@localhost') provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('10 10 10 10 *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4') end let(:instance) { provider.class.instances.first } describe 'self.instances' do it 'returns an array of users MySQL 5.5' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.5'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') end usernames = provider.class.instances.collect {|x| x.name } expect(parsed_users).to match_array(usernames) end it 'returns an array of users MySQL 5.6' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.6'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') end usernames = provider.class.instances.collect {|x| x.name } expect(parsed_users).to match_array(usernames) end it 'returns an array of users MySQL >= 5.7.0 < 5.7.6' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') end usernames = provider.class.instances.collect {|x| x.name } expect(parsed_users).to match_array(usernames) end it 'returns an array of users MySQL >= 5.7.6' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, AUTHENTICATION_STRING, PLUGIN FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') end usernames = provider.class.instances.collect {|x| x.name } expect(parsed_users).to match_array(usernames) end it 'returns an array of users mariadb 10.0' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mariadb-10.0'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') end usernames = provider.class.instances.collect {|x| x.name } expect(parsed_users).to match_array(usernames) end it 'returns an array of users percona 5.5' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['percona-5.5'][:string]) provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) parsed_users.each do |user| provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, SSL_TYPE, SSL_CIPHER, X509_ISSUER, X509_SUBJECT, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') end usernames = provider.class.instances.collect {|x| x.name } expect(parsed_users).to match_array(usernames) end end describe 'mysql version and type detection' do mysql_version_string_hash.each do |name,line| version=line[:version] string=line[:string] mysql_type=line[:mysql_type] it "detects type '#{mysql_type}' with version '#{version}'" do provider.class.instance_variable_set(:@mysqld_version_string, string) expect(provider.mysqld_version).to eq(version) expect(provider.mysqld_type).to eq(mysql_type) end end end describe 'self.prefetch' do it 'exists' do provider.class.instances provider.class.prefetch({}) end end describe 'create' do it 'makes a user' do provider.expects(:mysql).with([defaults_file, system_database, '-e', "CREATE USER 'joe'@'localhost' IDENTIFIED BY PASSWORD '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4'"]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10"]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE NONE"]) provider.expects(:exists?).returns(true) expect(provider.create).to be_truthy end end describe 'destroy' do it 'removes a user if present' do provider.expects(:mysql).with([defaults_file, system_database, '-e', "DROP USER 'joe'@'localhost'"]) provider.expects(:exists?).returns(false) expect(provider.destroy).to be_truthy end end describe 'exists?' do it 'checks if user exists' do expect(instance.exists?).to be_truthy end end describe 'self.mysqld_version' do it 'uses the mysqld_version fact if unset' do provider.class.instance_variable_set(:@mysqld_version_string, nil) Facter.stubs(:value).with(:mysqld_version).returns('5.6.24') expect(provider.mysqld_version).to eq '5.6.24' end it 'returns 5.7.6 for "mysqld Ver 5.7.6 for Linux on x86_64 (MySQL Community Server (GPL))"' do provider.class.instance_variable_set(:@mysqld_version_string, 'mysqld Ver 5.7.6 for Linux on x86_64 (MySQL Community Server (GPL))') expect(provider.mysqld_version).to eq '5.7.6' end it 'returns 5.7.6 for "mysqld Ver 5.7.6-rc for Linux on x86_64 (MySQL Community Server (GPL))"' do provider.class.instance_variable_set(:@mysqld_version_string, 'mysqld Ver 5.7.6-rc for Linux on x86_64 (MySQL Community Server (GPL))') expect(provider.mysqld_version).to eq '5.7.6' end it 'detects >= 5.7.6 for 5.7.7-log' do provider.class.instance_variable_set(:@mysqld_version_string, 'mysqld Ver 5.7.7-log for Linux on x86_64 (MySQL Community Server (GPL))') expect(Puppet::Util::Package.versioncmp(provider.mysqld_version, '5.7.6')).to be >= 0 end it 'detects < 5.7.6 for 5.7.5-log' do provider.class.instance_variable_set(:@mysqld_version_string, 'mysqld Ver 5.7.5-log for Linux on x86_64 (MySQL Community Server (GPL))') expect(Puppet::Util::Package.versioncmp(provider.mysqld_version, '5.7.6')).to be < 0 end end describe 'self.defaults_file' do it 'sets --defaults-extra-file' do File.stubs(:file?).with('/root/.my.cnf').returns(true) expect(provider.defaults_file).to eq '--defaults-extra-file=/root/.my.cnf' end it 'fails if file missing' do File.expects(:file?).with('/root/.my.cnf').returns(false) expect(provider.defaults_file).to be_nil end end describe 'password_hash' do it 'returns a hash' do expect(instance.password_hash).to eq('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4') end end describe 'password_hash=' do it 'changes the hash mysql 5.5' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.5'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "SET PASSWORD FOR 'joe'@'localhost' = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') provider.password_hash=('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') end it 'changes the hash mysql 5.6' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.6'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "SET PASSWORD FOR 'joe'@'localhost' = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') provider.password_hash=('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') end it 'changes the hash mysql < 5.7.6' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "SET PASSWORD FOR 'joe'@'localhost' = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') provider.password_hash=('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') end it 'changes the hash MySQL >= 5.7.6' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "ALTER USER 'joe'@'localhost' IDENTIFIED WITH mysql_native_password AS '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') provider.password_hash=('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') end it 'changes the hash mariadb-10.0' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mariadb-10.0'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "SET PASSWORD FOR 'joe'@'localhost' = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') provider.password_hash=('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') end it 'changes the hash percona-5.5' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['percona-5.5'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "SET PASSWORD FOR 'joe'@'localhost' = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') provider.password_hash=('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') end end describe 'tls_options=' do it 'adds SSL option grant in mysql 5.5' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.5'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE NONE"]).returns('0') provider.expects(:tls_options).returns(['NONE']) provider.tls_options=(['NONE']) end it 'adds SSL option grant in mysql 5.6' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.6'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE NONE"]).returns('0') provider.expects(:tls_options).returns(['NONE']) provider.tls_options=(['NONE']) end it 'adds SSL option grant in mysql < 5.7.6' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.1'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE NONE"]).returns('0') provider.expects(:tls_options).returns(['NONE']) provider.tls_options=(['NONE']) end it 'adds SSL option grant in mysql >= 5.7.6' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mysql-5.7.6'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "ALTER USER 'joe'@'localhost' REQUIRE NONE"]).returns('0') provider.expects(:tls_options).returns(['NONE']) provider.tls_options=(['NONE']) end it 'adds SSL option grant in mariadb-10.0' do provider.class.instance_variable_set(:@mysqld_version_string, mysql_version_string_hash['mariadb-10.0'][:string]) provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' REQUIRE NONE"]).returns('0') provider.expects(:tls_options).returns(['NONE']) provider.tls_options=(['NONE']) end end ['max_user_connections', 'max_connections_per_hour', 'max_queries_per_hour', 'max_updates_per_hour'].each do |property| describe property do it "returns #{property}" do expect(instance.send("#{property}".to_sym)).to eq('10') end end describe "#{property}=" do it "changes #{property}" do provider.expects(:mysql).with([defaults_file, system_database, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' WITH #{property.upcase} 42"]).returns('0') provider.expects(property.to_sym).returns('42') provider.send("#{property}=".to_sym, '42') end end end end puppetlabs-mysql-3.10.0/spec/defines/0000755005276200011600000000000013010160602017341 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/spec/defines/mysql_db_spec.rb0000644005276200011600000000645613010160217022527 0ustar jenkinsjenkinsrequire 'spec_helper' describe 'mysql::db', :type => :define do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts.merge({ :root_home => '/root', }) } let(:title) { 'test_db' } let(:params) { { 'user' => 'testuser', 'password' => 'testpass', } } it 'should report an error when ensure is not present or absent' do params.merge!({'ensure' => 'invalid_val'}) expect { catalogue }.to raise_error(Puppet::Error, /invalid_val is not supported for ensure\. Allowed values are 'present' and 'absent'\./) end it 'should not notify the import sql exec if no sql script was provided' do is_expected.to contain_mysql_database('test_db').without_notify end it 'should subscribe to database if sql script is given' do params.merge!({'sql' => 'test_sql'}) is_expected.to contain_exec('test_db-import').with_subscribe('Mysql_database[test_db]') end it 'should only import sql script on creation if not enforcing' do params.merge!({'sql' => 'test_sql', 'enforce_sql' => false}) is_expected.to contain_exec('test_db-import').with_refreshonly(true) end it 'should import sql script on creation if enforcing' do params.merge!({'sql' => 'test_sql', 'enforce_sql' => true}) is_expected.to contain_exec('test_db-import').with_refreshonly(false) is_expected.to contain_exec('test_db-import').with_command('cat test_sql | mysql test_db') end it 'should import sql script with custom command on creation if enforcing' do params.merge!({'sql' => 'test_sql', 'enforce_sql' => true, 'import_cat_cmd' => 'zcat'}) is_expected.to contain_exec('test_db-import').with_refreshonly(false) is_expected.to contain_exec('test_db-import').with_command('zcat test_sql | mysql test_db') end it 'should import sql scripts when more than one is specified' do params.merge!({'sql' => ['test_sql', 'test_2_sql']}) is_expected.to contain_exec('test_db-import').with_command('cat test_sql test_2_sql | mysql test_db') end it 'should report an error if sql isn\'t a string or an array' do params.merge!({'sql' => {'foo' => 'test_sql', 'bar' => 'test_2_sql'}}) expect { catalogue }.to raise_error(Puppet::Error, /\$sql must be either a string or an array\./) end it 'should not create database and database user' do params.merge!({'ensure' => 'absent', 'host' => 'localhost'}) is_expected.to contain_mysql_database('test_db').with_ensure('absent') is_expected.to contain_mysql_user('testuser@localhost').with_ensure('absent') end it 'should create with an appropriate collate and charset' do params.merge!({'charset' => 'utf8', 'collate' => 'utf8_danish_ci'}) is_expected.to contain_mysql_database('test_db').with({ 'charset' => 'utf8', 'collate' => 'utf8_danish_ci', }) end it 'should use dbname parameter as database name instead of name' do params.merge!({'dbname' => 'real_db'}) is_expected.to contain_mysql_database('real_db') end end end end puppetlabs-mysql-3.10.0/spec/spec_helper.rb0000644005276200011600000000033512746170223020562 0ustar jenkinsjenkins#This file is generated by ModuleSync, do not edit. require 'puppetlabs_spec_helper/module_spec_helper' # put local configuration and setup into spec_helper_local begin require 'spec_helper_local' rescue LoadError end puppetlabs-mysql-3.10.0/spec/spec_helper_acceptance.rb0000644005276200011600000000503612746170223022733 0ustar jenkinsjenkinsrequire 'beaker-rspec' require 'beaker/puppet_install_helper' run_puppet_install_helper UNSUPPORTED_PLATFORMS = [ 'Windows', 'Solaris', 'AIX' ] RSpec.configure do |c| # Project root proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) # Readable test descriptions c.formatter = :documentation # detect the situation where PUP-5016 is triggered and skip the idempotency tests in that case # also note how fact('puppetversion') is not available because of PUP-4359 if fact('osfamily') == 'Debian' && fact('operatingsystemmajrelease') == '8' && shell('puppet --version').stdout =~ /^4\.2/ c.filter_run_excluding :skip_pup_5016 => true end # Configure all nodes in nodeset c.before :suite do # Install module and dependencies puppet_module_install(:source => proj_root, :module_name => 'mysql') hosts.each do |host| # Required for binding tests. if fact('osfamily') == 'RedHat' version = fact("operatingsystemmajrelease") if fact('operatingsystemmajrelease') =~ /7/ || fact('operatingsystem') =~ /Fedora/ shell("yum install -y bzip2") end end # Solaris 11 doesn't ship the SSL CA root for the forgeapi server # therefore we need to use a different way to deploy the module to # the host if host['platform'] =~ /solaris-11/i apply_manifest_on(host, 'package { "git": }') # PE 3.x and 2015.2 require different locations to install modules modulepath = host.puppet['modulepath'] modulepath = modulepath.split(':').first if modulepath environmentpath = host.puppet['environmentpath'] environmentpath = environmentpath.split(':').first if environmentpath destdir = modulepath || "#{environmentpath}/production/modules" on host, "git clone https://github.com/puppetlabs/puppetlabs-stdlib #{destdir}/stdlib && cd #{destdir}/stdlib && git checkout 3.2.0" on host, "git clone https://github.com/stahnma/puppet-module-epel.git #{destdir}/epel && cd #{destdir}/epel && git checkout 1.0.2" else on host, puppet('module','install','puppetlabs-stdlib','--version','3.2.0') on host, puppet('module','install','stahnma/epel') on host, puppet('module','install','puppet/staging') end end end end shared_examples "a idempotent resource" do it 'should apply with no errors' do apply_manifest(pp, :catch_failures => true) end it 'should apply a second time without changes', :skip_pup_5016 do apply_manifest(pp, :catch_changes => true) end end puppetlabs-mysql-3.10.0/NOTICE0000644005276200011600000000120312746170223015711 0ustar jenkinsjenkinsmysql puppet module Copyright (C) 2013-2016 Puppet Labs, Inc. Puppet Labs can be contacted at: info@puppetlabs.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. puppetlabs-mysql-3.10.0/LICENSE0000644005276200011600000002613612746170223016026 0ustar jenkinsjenkins Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. puppetlabs-mysql-3.10.0/examples/0000755005276200011600000000000013010160602016610 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/examples/mysql_database.pp0000644005276200011600000000052012746170223022156 0ustar jenkinsjenkinsclass { 'mysql::server': root_password => 'password' } mysql::db{ ['test1', 'test2', 'test3']: ensure => present, charset => 'utf8', require => Class['mysql::server'], } mysql::db{ 'test4': ensure => present, charset => 'latin1', } mysql::db{ 'test5': ensure => present, charset => 'binary', collate => 'binary', } puppetlabs-mysql-3.10.0/examples/java.pp0000644005276200011600000000003012746170223020102 0ustar jenkinsjenkinsclass { 'mysql::java':} puppetlabs-mysql-3.10.0/examples/mysql_db.pp0000644005276200011600000000056412746170223021007 0ustar jenkinsjenkinsclass { 'mysql::server': root_password => 'password' } mysql::db { 'mydb': user => 'myuser', password => 'mypass', host => 'localhost', grant => ['SELECT', 'UPDATE'], } mysql::db { "mydb_${fqdn}": user => 'myuser', password => 'mypass', dbname => 'mydb', host => $::fqdn, grant => ['SELECT', 'UPDATE'], tag => $domain, } puppetlabs-mysql-3.10.0/examples/perl.pp0000644005276200011600000000003612746170223020131 0ustar jenkinsjenkinsinclude mysql::bindings::perl puppetlabs-mysql-3.10.0/examples/bindings.pp0000644005276200011600000000006312746170223020764 0ustar jenkinsjenkinsclass { 'mysql::bindings': php_enable => true, } puppetlabs-mysql-3.10.0/examples/mysql_plugin.pp0000644005276200011600000000072512746170223021717 0ustar jenkinsjenkinsclass { 'mysql::server': root_password => 'password' } $validate_password_soname = $::osfamily ? { windows => 'validate_password.dll', default => 'validate_password.so' } mysql::plugin { 'validate_password': ensure => present, soname => $validate_password_soname, } $auth_socket_soname = $::osfamily ? { windows => 'auth_socket.dll', default => 'auth_socket.so' } mysql::plugin { 'auth_socket': ensure => present, soname => $auth_socket_soname, } puppetlabs-mysql-3.10.0/examples/ruby.pp0000644005276200011600000000003612746170223020150 0ustar jenkinsjenkinsinclude mysql::bindings::ruby puppetlabs-mysql-3.10.0/examples/backup.pp0000644005276200011600000000030112746170223020427 0ustar jenkinsjenkinsclass { 'mysql::server': root_password => 'password' } class { 'mysql::server::backup': backupuser => 'myuser', backuppassword => 'mypassword', backupdir => '/tmp/backups', } puppetlabs-mysql-3.10.0/examples/mysql_user.pp0000644005276200011600000000123212746170223021371 0ustar jenkinsjenkins$mysql_root_pw = 'password' class { 'mysql::server': root_password => 'password', } mysql_user{ 'redmine@localhost': ensure => present, password_hash => mysql_password('redmine'), require => Class['mysql::server'], } mysql_user{ 'dan@localhost': ensure => present, password_hash => mysql_password('blah') } mysql_user{ 'dan@%': ensure => present, password_hash => mysql_password('blah'), } mysql_user{ 'socketplugin@%': ensure => present, plugin => 'unix_socket', } mysql_user{ 'socketplugin@%': ensure => present, password_hash => mysql_password('blah'), plugin => 'mysql_native_password', } puppetlabs-mysql-3.10.0/examples/server.pp0000644005276200011600000000007212746170223020475 0ustar jenkinsjenkinsclass { 'mysql::server': root_password => 'password', } puppetlabs-mysql-3.10.0/examples/mysql_grant.pp0000644005276200011600000000020712746170223021527 0ustar jenkinsjenkinsmysql_grant{'test1@localhost/redmine.*': user => 'test1@localhost', table => 'redmine.*', privileges => ['UPDATE'], } puppetlabs-mysql-3.10.0/examples/server/0000755005276200011600000000000013010160602020116 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/examples/server/config.pp0000644005276200011600000000004712746170223021744 0ustar jenkinsjenkinsmysql::server::config { 'testfile': } puppetlabs-mysql-3.10.0/examples/server/account_security.pp0000644005276200011600000000014712746170223024063 0ustar jenkinsjenkinsclass { 'mysql::server': root_password => 'password', } class { 'mysql::server::account_security': } puppetlabs-mysql-3.10.0/examples/python.pp0000644005276200011600000000004412746170223020507 0ustar jenkinsjenkinsclass { 'mysql::bindings::python':} puppetlabs-mysql-3.10.0/Gemfile0000644005276200011600000000341213010160217016267 0ustar jenkinsjenkins#This file is generated by ModuleSync, do not edit. source ENV['GEM_SOURCE'] || "https://rubygems.org" def location_from_env(env, default_location = []) if location = ENV[env] if location =~ /^((?:git|https?)[:@][^#]*)#(.*)/ [{ :git => $1, :branch => $2, :require => false }] elsif location =~ /^file:\/\/(.*)/ ['>= 0', { :path => File.expand_path($1), :require => false }] else [location, { :require => false }] end else default_location end end group :development, :unit_tests do gem 'metadata-json-lint' gem 'puppet_facts' gem 'puppet-blacksmith', '>= 3.4.0' gem 'puppetlabs_spec_helper', '>= 1.2.1' gem 'rspec-puppet', '>= 2.3.2' gem 'rspec-puppet-facts' gem 'mocha', '< 1.2.0' gem 'simplecov' gem 'parallel_tests', '< 2.10.0' if RUBY_VERSION < '2.0.0' gem 'parallel_tests' if RUBY_VERSION >= '2.0.0' gem 'rubocop', '0.41.2' if RUBY_VERSION < '2.0.0' gem 'rubocop' if RUBY_VERSION >= '2.0.0' gem 'rubocop-rspec', '~> 1.6' if RUBY_VERSION >= '2.3.0' gem 'json_pure', '<= 2.0.1' if RUBY_VERSION < '2.0.0' gem 'rspec-puppet-facts' end group :system_tests do gem 'beaker', *location_from_env('BEAKER_VERSION', []) if RUBY_VERSION >= '2.3.0' gem 'beaker', *location_from_env('BEAKER_VERSION', ['< 3']) if RUBY_VERSION < '2.3.0' gem 'beaker-pe' if RUBY_VERSION >= '2.3.0' gem 'beaker-rspec', *location_from_env('BEAKER_RSPEC_VERSION', ['>= 3.4']) gem 'serverspec' gem 'beaker-puppet_install_helper' gem 'master_manipulator' gem 'beaker-hostgenerator', *location_from_env('BEAKER_HOSTGENERATOR_VERSION', []) end gem 'facter', *location_from_env('FACTER_GEM_VERSION') gem 'puppet', *location_from_env('PUPPET_GEM_VERSION') if File.exists? "#{__FILE__}.local" eval(File.read("#{__FILE__}.local"), binding) end puppetlabs-mysql-3.10.0/metadata.json0000644005276200011600000000321113010160602017442 0ustar jenkinsjenkins{ "name": "puppetlabs-mysql", "version": "3.10.0", "author": "Puppet Labs", "summary": "Installs, configures, and manages the MySQL service.", "license": "Apache-2.0", "source": "git://github.com/puppetlabs/puppetlabs-mysql.git", "project_page": "http://github.com/puppetlabs/puppetlabs-mysql", "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", "dependencies": [ {"name":"puppetlabs/stdlib","version_requirement":">= 3.2.0 < 5.0.0"}, {"name":"puppet/staging","version_requirement":">= 1.0.1 < 3.0.0"} ], "data_provider": null, "operatingsystem_support": [ { "operatingsystem": "RedHat", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "Scientific", "operatingsystemrelease": [ "5", "6", "7" ] }, { "operatingsystem": "SLES", "operatingsystemrelease": [ "11 SP1", "12" ] }, { "operatingsystem": "Debian", "operatingsystemrelease": [ "6", "7", "8" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ "10.04", "12.04", "14.04", "16.04" ] } ], "requirements": [ { "name": "puppet", "version_requirement": ">= 3.0.0 < 5.0.0" } ], "description": "MySQL module" } puppetlabs-mysql-3.10.0/checksums.json0000644005276200011600000001777213010160602017670 0ustar jenkinsjenkins{ "CHANGELOG.md": "b68d316974b7228a92b8a8c3b65bb9a4", "CONTRIBUTING.md": "b78f71c1104f00538d50ad2775f58e95", "Gemfile": "fda543906c8c75b06ea37c4d31b95292", "LICENSE": "3b83ef96387f14655fc854ddc3c6bd57", "NOTICE": "d43aacde256c8e55a50e2425e25b3a8a", "README.md": "b4969d0b8649dd0f9c105ff22b66a871", "Rakefile": "6db744f1deed7ae0746abe59e3d50863", "TODO": "88ca4024a37992b46c34cb46e4ac39e6", "examples/backup.pp": "a61c6f34f153a323209faf25948737f5", "examples/bindings.pp": "35a8387f5c55fa2e479c513a67918674", "examples/java.pp": "0ad9de4f9f2c049642bcf08124757085", "examples/mysql_database.pp": "107ee8793f7b4a12cfca32eddccc6bbd", "examples/mysql_db.pp": "55d2d603f9fb8ab3c8a781d08119aa69", "examples/mysql_grant.pp": "cd42336a6c7b2d27f5d5d6d0e310ee1a", "examples/mysql_plugin.pp": "4f86c988a99b131e736501a309604e94", "examples/mysql_user.pp": "0b76964aebb01714745548e0f2f32fd3", "examples/perl.pp": "454f14dc4492fcf04afbe81b2776917e", "examples/python.pp": "355a7e1ea3978a8fd290b5bc28b63808", "examples/ruby.pp": "a6ae0381aacc5a8d2c403e606c6df0f0", "examples/server/account_security.pp": "375442b7886c01b42fbf75a1fcb31822", "examples/server/config.pp": "659b7c40e9b55634721b3c33a8c6da98", "examples/server.pp": "72e22552a95b9a5e4a349dbfc13639dc", "lib/facter/mysql_server_id.rb": "10de205ca9dc83b68cf63b52d97346ec", "lib/facter/mysql_version.rb": "e30648f3d394a1cbdd4e54eb5c28d28c", "lib/facter/mysqld_version.rb": "720f447c97dd4ce099006cd5391ade57", "lib/puppet/parser/functions/mysql_deepmerge.rb": "2b5040ee8cd75a81cf881851e922833a", "lib/puppet/parser/functions/mysql_dirname.rb": "820ba09a6a0df639da560b41cb31242f", "lib/puppet/parser/functions/mysql_password.rb": "365a0ba55f0d04d0f5d56abcd577ec7d", "lib/puppet/parser/functions/mysql_strip_hash.rb": "3efe69f1eb189b2913e178b8472aaede", "lib/puppet/provider/mysql.rb": "2696893220da9d341d5826c9e9d4ca19", "lib/puppet/provider/mysql_database/mysql.rb": "5cf9b8044df4ec72a726b5f781c84f8f", "lib/puppet/provider/mysql_datadir/mysql.rb": "7c256b40cf96bdafde9c762ab867de80", "lib/puppet/provider/mysql_grant/mysql.rb": "3630023349a4c8f06932938a26aaa2e6", "lib/puppet/provider/mysql_plugin/mysql.rb": "49128d2a9a547c4945735bfd75fd6d6c", "lib/puppet/provider/mysql_user/mysql.rb": "dc09eef4e1d879ffe4ee8eb9a7b3026c", "lib/puppet/type/mysql_database.rb": "438eafbfecc30605462a220d92cf9603", "lib/puppet/type/mysql_datadir.rb": "f19e548062e81f424646c193b086aaf6", "lib/puppet/type/mysql_grant.rb": "afcc65b0394a23e95b8bf932bc6110b4", "lib/puppet/type/mysql_plugin.rb": "0a52cead6c9283c9aa14ea71bdfa80bd", "lib/puppet/type/mysql_user.rb": "8cc3c0851c06d01b310a7f551945e696", "manifests/backup/mysqlbackup.pp": "66441b167e682689df21a4b37af175e8", "manifests/backup/mysqldump.pp": "d858a7dda445c45952f6a7f029d41189", "manifests/backup/xtrabackup.pp": "ebf4f4765fbbedbdc49acad9dd539a6b", "manifests/bindings/client_dev.pp": "80753f1bf48de71d2ca1a6cfda4830be", "manifests/bindings/daemon_dev.pp": "94d2d74afc2b247593877cebd548ed76", "manifests/bindings/java.pp": "556b743dc162d2f3264708b0b7ba0328", "manifests/bindings/perl.pp": "4ecbd448ceac580a07df34b5d3e24837", "manifests/bindings/php.pp": "641139f1f27085b8e72ac73fb8bc39d8", "manifests/bindings/python.pp": "ef9e674237eddd7e98ab307131b11069", "manifests/bindings/ruby.pp": "32b0a32161f7a5b50562cb8e154207d9", "manifests/bindings.pp": "8becf04105d44910f12986a58cd566f7", "manifests/client/install.pp": "7b5810404cc9411ec38de404749f1266", "manifests/client.pp": "c350bd6d108acb03a87b860b14d225ef", "manifests/db.pp": "fada45e451ec7563dab714d12b9e330b", "manifests/params.pp": "816c5cf78525ab2917da4ce1a888dfe6", "manifests/server/account_security.pp": "36a293eec189ec1bdfe92b370d087085", "manifests/server/backup.pp": "6ed4f8c9aac5d7f17bf5c10fceddde41", "manifests/server/binarylog.pp": "d61af28d0f9c07cfa23c63a7cdd364bf", "manifests/server/config.pp": "650f0ba40b9148e66f910465e63b1170", "manifests/server/install.pp": "3cbbf313b940b582e73c229f4a8c0720", "manifests/server/installdb.pp": "ccc13d3cbeb78b0c144006a256e40079", "manifests/server/monitor.pp": "3810b5d756a3661e92d709115982cd59", "manifests/server/mysqltuner.pp": "24d04e0b24cf3b31b6798bc76eed32b6", "manifests/server/providers.pp": "87a019dce5bbb6b18c9aa61b5f99134c", "manifests/server/root_password.pp": "5790e04defe2a64d145975abdfcfd3ac", "manifests/server/service.pp": "e9d4256c2830a8b300822616c408ce95", "manifests/server.pp": "3f3915a73ff075eca009f5656b225e6d", "metadata.json": "2cc79c0e6902c12c1b33eca2e192ea29", "spec/acceptance/mysql_backup_spec.rb": "ef6f0d033e87a8a9f8457f89ad8ea118", "spec/acceptance/mysql_db_spec.rb": "c093f0d25c7000713b444706b6cfd1c7", "spec/acceptance/mysql_helper.rb": "b95d8fd15325f1ece1cd652dc60c7608", "spec/acceptance/mysql_server_spec.rb": "b3362859a6cdc38cfabf1c5a63a4fc57", "spec/acceptance/nodesets/centos-7-x64.yml": "a713f3abd3657f0ae2878829badd23cd", "spec/acceptance/nodesets/debian-8-x64.yml": "d2d2977900989f30086ad251a14a1f39", "spec/acceptance/nodesets/default.yml": "b42da5a1ea0c964567ba7495574b8808", "spec/acceptance/nodesets/docker/centos-7.yml": "8a3892807bdd62306ae4774f41ba11ae", "spec/acceptance/nodesets/docker/debian-8.yml": "ac8e871d1068c96de5e85a89daaec6df", "spec/acceptance/nodesets/docker/ubuntu-14.04.yml": "dc42ee922a96908d85b8f0f08203ce58", "spec/acceptance/types/mysql_database_spec.rb": "047db055103fa9782bc6714297eb2a09", "spec/acceptance/types/mysql_grant_spec.rb": "216d93f0937dbdb5fc58a61bd2150d62", "spec/acceptance/types/mysql_plugin_spec.rb": "107f32d267daa847996ff992ccec8c06", "spec/acceptance/types/mysql_user_spec.rb": "5d04dc3b3ffd0778f83038833ef72bf2", "spec/classes/graceful_failures_spec.rb": "91481f693c3f71dff22524189438bcc6", "spec/classes/mycnf_template_spec.rb": "07fc36d51b592eba1f94d39208c2701f", "spec/classes/mysql_bindings_spec.rb": "14c5abbe4ae20278d1a4a02254bf312b", "spec/classes/mysql_client_spec.rb": "b1fa7a5a06585697f7100d1891d359ed", "spec/classes/mysql_server_account_security_spec.rb": "97b6caf04a7a75a88e58728edcfc11cb", "spec/classes/mysql_server_backup_spec.rb": "964357b46daa237c92cc61b88a20093b", "spec/classes/mysql_server_monitor_spec.rb": "aef3aa73265b42b66b963a09e5f32f1f", "spec/classes/mysql_server_mysqltuner_spec.rb": "55ff6dad45a8dfef97d52dff0b111a36", "spec/classes/mysql_server_spec.rb": "99806ad51b124bf8ca9dad201962b743", "spec/defines/mysql_db_spec.rb": "afb2d6cfa051dd4d8301d7aede1aa1c4", "spec/spec.opts": "a600ded995d948e393fbe2320ba8e51c", "spec/spec_helper.rb": "b2db3bc02b4ac2fd5142a6621c641b07", "spec/spec_helper_acceptance.rb": "2d7d8e8a6d1225ba6bf57a4f05dfff0c", "spec/spec_helper_local.rb": "05db024c91eb5d5141b67d97b01a58b4", "spec/unit/facter/mysql_server_id_spec.rb": "4a01f2323a400c82d89f37847c3c9611", "spec/unit/facter/mysql_version_spec.rb": "f593c725b83a7bbf1f0fdc13bf1531df", "spec/unit/facter/mysqld_version_spec.rb": "f5495c63a64d21be175d329cc5a3a8cd", "spec/unit/puppet/functions/mysql_deepmerge_spec.rb": "f6102e1f82fb9f4aa38cbf3955ee5973", "spec/unit/puppet/functions/mysql_password_spec.rb": "8fe68dc4ec13fc6ade18defe54cac8d4", "spec/unit/puppet/provider/mysql_database/mysql_spec.rb": "98a799433ac10b237ac3ad27441610d4", "spec/unit/puppet/provider/mysql_plugin/mysql_spec.rb": "914bac73bb9841ec7d7041488a55d442", "spec/unit/puppet/provider/mysql_user/mysql_spec.rb": "174e7e3a97529fdcc2e6ba24e65cf8d2", "spec/unit/puppet/type/mysql_database_spec.rb": "9fa0d390c2e15c8a52fc2b981e2a63fc", "spec/unit/puppet/type/mysql_grant_spec.rb": "1a003358dc88a74ef21fb33fc71debef", "spec/unit/puppet/type/mysql_plugin_spec.rb": "7ebacf228dfd0c60811bdf8a28a329ff", "spec/unit/puppet/type/mysql_user_spec.rb": "e902ad1b9578dce35e13750c7967ef1d", "templates/meb.cnf.erb": "b6422b19ee97b8a2883bfac44fdc0292", "templates/my.cnf.erb": "535d2ff37fea6b11ad928224965143d3", "templates/my.cnf.pass.erb": "11f80afb0993a436f074a43f70733999", "templates/mysqlbackup.sh.erb": "0cc74138c7a5dd5d3864f94227717bd4", "templates/xtrabackup.sh.erb": "219b487c4faad80a897cda6973b81741" }puppetlabs-mysql-3.10.0/README.md0000644005276200011600000010071713010160217016261 0ustar jenkinsjenkins# mysql #### Table of Contents 1. [Module Description - What the module does and why it is useful](#module-description) 2. [Setup - The basics of getting started with mysql](#setup) * [Beginning with mysql](#beginning-with-mysql) 3. [Usage - Configuration options and additional functionality](#usage) * [Customize server options](#customize-server-options) * [Create a database](#create-a-database) * [Customize configuration](#create-custom-configuration) * [Work with an existing server](#work-with-an-existing-server) * [Specify passwords](#specify-passwords) * [Install Percona server on CentOS](#install-percona-server-on-centos) * [Install MariaDB on Ubuntu](#install-mariadb-on-ubuntu) 4. [Reference - An under-the-hood peek at what the module is doing and how](#reference) 5. [Limitations - OS compatibility, etc.](#limitations) 6. [Development - Guide for contributing to the module](#development) ## Module Description The mysql module installs, configures, and manages the MySQL service. This module manages both the installation and configuration of MySQL, as well as extending Puppet to allow management of MySQL resources, such as databases, users, and grants. ## Setup ### Beginning with mysql To install a server with the default options: `include '::mysql::server'`. To customize options, such as the root password or `/etc/my.cnf` settings, you must also pass in an override hash: ```puppet class { '::mysql::server': root_password => 'strongpassword', remove_default_accounts => true, override_options => $override_options } ``` See [**Customize Server Options**](#customize-server-options) below for examples of the hash structure for $override_options`. ## Usage All interaction for the server is done via `mysql::server`. To install the client, use `mysql::client`. To install bindings, use `mysql::bindings`. ### Customize server options To define server options, structure a hash structure of overrides in `mysql::server`. This hash resembles a hash in the my.cnf file: ```puppet $override_options = { 'section' => { 'item' => 'thing', } } ``` For options that you would traditionally represent in this format: ``` [section] thing = X ``` ...you can make an entry like `thing => true`, `thing => value`, or `thing => "` in the hash. Alternatively, you can pass an array, as `thing => ['value', 'value2']`, or list each `thing => value` separately on separate lines. You can pass a variable in the hash without setting a value for it; the variable would then use MySQL's default settings. To exclude an option from the my.cnf file --- for example, when using `override_options` to revert to a default value --- pass `thing => undef`. If an option needs multiple instances, pass an array. For example, ```puppet $override_options = { 'mysqld' => { 'replicate-do-db' => ['base1', 'base2'], } } ``` produces ``` [mysqld] replicate-do-db = base1 replicate-do-db = base2 ``` To implement version specific parameters, specify the version, such as [mysqld-5.5]. This allows one config for different versions of MySQL. ### Create a database To create a database with a user and some assigned privileges: ```puppet mysql::db { 'mydb': user => 'myuser', password => 'mypass', host => 'localhost', grant => ['SELECT', 'UPDATE'], } ``` To use a different resource name with exported resources: ```puppet @@mysql::db { "mydb_${fqdn}": user => 'myuser', password => 'mypass', dbname => 'mydb', host => ${fqdn}, grant => ['SELECT', 'UPDATE'], tag => $domain, } ``` Then you can collect it on the remote DB server: ```puppet Mysql::Db <<| tag == $domain |>> ``` If you set the sql parameter to a file when creating a database, the file is imported into the new database. For large sql files, increase the `import_timeout` parameter, which defaults to 300 seconds. ```puppet mysql::db { 'mydb': user => 'myuser', password => 'mypass', host => 'localhost', grant => ['SELECT', 'UPDATE'], sql => '/path/to/sqlfile.gz', import_cat_cmd => 'zcat', import_timeout => 900, } ``` ### Customize configuration To add custom MySQL configuration, place additional files into `includedir`. This allows you to override settings or add additional ones, which is helpful if you don't use `override_options` in `mysql::server`. The `includedir` location is by default set to `/etc/mysql/conf.d`. ### Work with an existing server To instantiate databases and users on an existing MySQL server, you need a `.my.cnf` file in `root`'s home directory. This file must specify the remote server address and credentials. For example: ``` [client] user=root host=localhost password=secret ``` This module uses the `mysqld_version` fact to discover the server version being used. By default, this is set to the output of `mysqld -V`. If you're working with a remote MySQL server, you may need to set a custom fact for `mysqld_version` to ensure correct behaviour. When working with a remote server, do *not* use the `mysql::server` class in your Puppet manifests. ### Specify passwords In addition to passing passwords as plain text, you can input them as hashes. For example: ```puppet mysql::db { 'mydb': user => 'myuser', password => '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4', host => 'localhost', grant => ['SELECT', 'UPDATE'], } ``` ### Install Percona server on CentOS This example shows how to do a minimal installation of a Percona server on a CentOS system. This sets up the Percona server, client, and bindings (including Perl and Python bindings). You can customize this usage and update the version as needed. This usage has been tested on Puppet 4.4 / CentOS 7 / Percona Server 5.7. **Note:** The installation of the yum repository is not part of this package and is here only to show a full example of how you can install. ```puppet yumrepo { 'percona': descr => 'CentOS $releasever - Percona', baseurl => 'http://repo.percona.com/centos/$releasever/os/$basearch/', gpgkey => 'http://www.percona.com/downloads/percona-release/RPM-GPG-KEY-percona', enabled => 1, gpgcheck => 1, } class {'mysql::server': package_name => 'Percona-Server-server-57', package_ensure => '5.7.11-4.1.el7', service_name => 'mysql', config_file => '/etc/my.cnf', includedir => '/etc/my.cnf.d', root_password => 'PutYourOwnPwdHere', override_options => { mysqld => { log-error => '/var/log/mysqld.log', pid-file => '/var/run/mysqld/mysqld.pid', }, mysqld_safe => { log-error => '/var/log/mysqld.log', }, } } # Note: Installing Percona-Server-server-57 also installs Percona-Server-client-57. # This shows how to install the Percona MySQL client on its own class {'mysql::client': package_name => 'Percona-Server-client-57', package_ensure => '5.7.11-4.1.el7', } # These packages are normally installed along with Percona-Server-server-57 # If you needed to install the bindings, however, you could do so with this code class { 'mysql::bindings': client_dev_package_name => 'Percona-Server-shared-57', client_dev_package_ensure => '5.7.11-4.1.el7', client_dev => true, daemon_dev_package_name => 'Percona-Server-devel-57', daemon_dev_package_ensure => '5.7.11-4.1.el7', daemon_dev => true, perl_enable => true, perl_package_name => 'perl-DBD-MySQL', python_enable => true, python_package_name => 'MySQL-python', } # Dependencies definition Yumrepo['percona']-> Class['mysql::server'] Yumrepo['percona']-> Class['mysql::client'] Yumrepo['percona']-> Class['mysql::bindings'] ``` ### Install MariaDB on Ubuntu #### Optional: Install the MariaDB official repo In this example, we'll use the latest stable (currently 10.1) from the official MariaDB repository, not the one from the distro repository. You could instead use the package from the Ubuntu repository. Make sure you use the repository corresponding to the version you want. **Note:** `sfo1.mirrors.digitalocean.com` is one of many mirrors available. You can use any official mirror. ``` include apt apt::source { 'mariadb': location => 'http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.1/ubuntu', release => $::lsbdistcodename, repos => 'main', key => { id => '199369E5404BD5FC7D2FE43BCBCB082A1BB943DB', server => 'hkp://keyserver.ubuntu.com:80', }, include => { src => false, deb => true, }, } ``` #### Install the MariaDB server This example shows MariaDB server installation on Ubuntu Trusty. Adjust the version and the parameters of `my.cnf` as needed. All parameters of the `my.cnf` can be defined using the `override_options` parameter. The folders `/var/log/mysql` and `/var/run/mysqld` are created automatically, but if you are using other custom folders, they should exist as prerequisites for this code. All the values set here are an example of a working minimal configuration. Specify the version of the package you want with the `package_ensure` parameter. ``` class {'::mysql::server': package_name => 'mariadb-server', package_ensure => '10.1.14+maria-1~trusty', service_name => 'mysql', root_password => 'AVeryStrongPasswordUShouldEncrypt!', override_options => { mysqld => { 'log-error' => '/var/log/mysql/mariadb.log', 'pid-file' => '/var/run/mysqld/mysqld.pid', }, mysqld_safe => { 'log-error' => '/var/log/mysql/mariadb.log', }, } } # Dependency management. Only use that part if you are installing the repository # as shown in the Preliminary step of this example. Apt::Source['mariadb'] ~> Class['apt::update'] -> Class['::mysql::server'] ``` #### Install the MariaDB client This example shows how to install the MariaDB client and all of the bindings at once. You can do this installation separately from the server installation. Specify the version of the package you want with the `package_ensure` parameter. ``` class {'::mysql::client': package_name => 'mariadb-client', package_ensure => '10.1.14+maria-1~trusty', bindings_enable => true, } # Dependency management. Only use that part if you are installing the repository # as shown in the Preliminary step of this example. Apt::Source['mariadb'] ~> Class['apt::update'] -> Class['::mysql::client'] ``` ## Reference ### Classes #### Public classes * [`mysql::server`](#mysqlserver): Installs and configures MySQL. * [`mysql::server::monitor`](#mysqlservermonitor): Sets up a monitoring user. * [`mysql::server::mysqltuner`](#mysqlservermysqltuner): Installs MySQL tuner script. * [`mysql::server::backup`](#mysqlserverbackup): Sets up MySQL backups via cron. * [`mysql::bindings`](#mysqlbindings): Installs various MySQL language bindings. * [`mysql::client`](#mysqlclient): Installs MySQL client (for non-servers). #### Private classes * `mysql::server::install`: Installs packages. * `mysql::server::installdb`: Implements setup of mysqld data directory (e.g. /var/lib/mysql) * `mysql::server::config`: Configures MYSQL. * `mysql::server::service`: Manages service. * `mysql::server::account_security`: Deletes default MySQL accounts. * `mysql::server::root_password`: Sets MySQL root password. * `mysql::server::providers`: Creates users, grants, and databases. * `mysql::bindings::client_dev`: Installs MySQL client development package. * `mysql::bindings::daemon_dev`: Installs MySQL daemon development package. * `mysql::bindings::java`: Installs Java bindings. * `mysql::bindings::perl`: Installs Perl bindings. * `mysql::bindings::php`: Installs PHP bindings. * `mysql::bindings::python`: Installs Python bindings. * `mysql::bindings::ruby`: Installs Ruby bindings. * `mysql::client::install`: Installs MySQL client. * `mysql::backup::mysqldump`: Implements mysqldump backups. * `mysql::backup::mysqlbackup`: Implements backups with Oracle MySQL Enterprise Backup. * `mysql::backup::xtrabackup`: Implements backups with XtraBackup from Percona. ### Parameters #### mysql::server ##### `create_root_user` Whether root user should be created. Valid values are true, false. Defaults to true. This is useful for a cluster setup with Galera. The root user has to be created only once. You can set this parameter true on one node and set it to false on the remaining nodes. ##### `create_root_my_cnf` Whether to create `/root/.my.cnf`. Valid values are true, false. Defaults to true. `create_root_my_cnf` allows creation of `/root/.my.cnf` independently of `create_root_user`. You can use this for a cluster setup with Galera where you want `/root/.my.cnf` to exist on all nodes. ##### `root_password` The MySQL root password. Puppet attempts to set the root password and update `/root/.my.cnf` with it. This is required if `create_root_user` or `create_root_my_cnf` are true. If `root_password` is 'UNSET', then `create_root_user` and `create_root_my_cnf` are assumed to be false --- that is, the MySQL root user and `/root/.my.cnf` are not created. Password changes are supported; however, the old password must be set in `/root/.my.cnf`. Effectively, Puppet uses the old password, configured in `/root/my.cnf`, to set the new password in MySQL, and then updates `/root/.my.cnf` with the new password. ##### `old_root_password` This parameter no longer does anything. It exists only for backwards compatibility. See the `root_password` parameter above for details on changing the root password. ##### `override_options` Specifies override options to pass into MySQL. Structured like a hash in the my.cnf file: ```puppet $override_options = { 'section' => { 'item' => 'thing', } } ``` See [**Customize Server Options**](#customize-server-options) above for usage details. ##### `config_file` The location, as a path, of the MySQL configuration file. ##### `manage_config_file` Whether the MySQL configuration file should be managed. Valid values are true, false. Defaults to true. ##### `includedir` The location, as a path, of !includedir for custom configuration overrides. ##### `install_options` Passes [install_options](https://docs.puppetlabs.com/references/latest/type.html#package-attribute-install_options) array to managed package resources. You must pass the appropriate options for the specified package manager. ##### `purge_conf_dir` Whether the `includedir` directory should be purged. Valid values are true, false. Defaults to false. ##### `restart` Whether the service should be restarted when things change. Valid values are true, false. Defaults to false. ##### `root_group` The name of the group used for root. Can be a group name or a group ID. See more about the [`group` file attribute](https://docs.puppetlabs.com/references/latest/type.html#file-attribute-group). ##### `mysql_group` The name of the group of the MySQL daemon user. Can be a group name or a group ID. See more about the [`group` file attribute](https://docs.puppetlabs.com/references/latest/type.html#file-attribute-group). ##### `package_ensure` Whether the package exists or should be a specific version. Valid values are 'present', 'absent', or 'x.y.z'. Defaults to 'present'. ##### `package_manage` Whether to manage the MySQL server package. Defaults to true. ##### `package_name` The name of the MySQL server package to install. ##### `remove_default_accounts` Specifies whether to automatically include `mysql::server::account_security`. Valid values are true, false. Defaults to false. ##### `service_enabled` Specifies whether the service should be enabled. Valid values are true, false. Defaults to true. ##### `service_manage` Specifies whether the service should be managed. Valid values are true, false. Defaults to true. ##### `service_name` The name of the MySQL server service. Defaults are OS dependent, defined in params.pp. ##### `service_provider` The provider to use to manage the service. For Ubuntu, defaults to 'upstart'; otherwise, default is undefined. ##### `users` Optional hash of users to create, which are passed to [mysql_user](#mysql_user). ``` users => { 'someuser@localhost' => { ensure => 'present', max_connections_per_hour => '0', max_queries_per_hour => '0', max_updates_per_hour => '0', max_user_connections => '0', password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF', tls_options => ['NONE'], }, } ``` ##### `grants` Optional hash of grants, which are passed to [mysql_grant](#mysql_grant). ``` grants => { 'someuser@localhost/somedb.*' => { ensure => 'present', options => ['GRANT'], privileges => ['SELECT', 'INSERT', 'UPDATE', 'DELETE'], table => 'somedb.*', user => 'someuser@localhost', }, } ``` ##### `databases` Optional hash of databases to create, which are passed to [mysql_database](#mysql_database). ``` databases => { 'somedb' => { ensure => 'present', charset => 'utf8', }, } ``` #### mysql::server::backup ##### `backupuser` MySQL user to create for backups. ##### `backuppassword` MySQL user password for backups. ##### `backupdir` Directory in which to store backups. ##### `backupdirmode` Permissions applied to the backup directory. This parameter is passed directly to the `file` resource. ##### `backupdirowner` Owner for the backup directory. This parameter is passed directly to the `file` resource. ##### `backupdirgroup` Group owner for the backup directory. This parameter is passed directly to the `file` resource. ##### `backupcompress` Whether backups should be compressed. Valid values are true, false. Defaults to true. ##### `backuprotate` How many days to keep backups. Valid value is an integer. Defaults to '30'. ##### `delete_before_dump` Whether to delete old .sql files before backing up. Setting to true deletes old files before backing up, while setting to false deletes them after backup. Valid values are true, false. Defaults to false. ##### `backupdatabases` Specifies an array of databases to back up. ##### `file_per_database` Whether a separate file be used per database. Valid values are true, false. Defaults to false. ##### `include_routines` Whether or not to include routines for each database when doing a `file_per_database` backup. Defaults to false. ##### `include_triggers` Whether or not to include triggers for each database when doing a `file_per_database` backup. Defaults to false. ##### `ensure` Allows you to remove the backup scripts. Valid values are 'present', 'absent'. Defaults to 'present'. ##### `execpath` Allows you to set a custom PATH should your MySQL installation be non-standard places. Defaults to `/usr/bin:/usr/sbin:/bin:/sbin`. ##### `time` An array of two elements to set the backup time. Allows ['23', '5'] (i.e., 23:05) or ['3', '45'] (i.e., 03:45) for HH:MM times. ##### `postscript` A script that is executed when the backup is finished. This could be used to (r)sync the backup to a central store. This script can be either a single line that is directly executed or a number of lines supplied as an array. It could also be one or more externally managed (executable) files. ##### `prescript` A script that is executed before the backup begins. ##### `provider` Sets the server backup implementation. Valid values are: * `mysqldump`: Implements backups with mysqldump. Backup type: Logical. This is the default value. * `mysqlbackup`: Implements backups with MySQL Enterprise Backup from Oracle. Backup type: Physical. To use this type of backup, you'll need the `meb` package, which is available in RPM and TAR formats from Oracle. For Ubuntu, you can use [meb-deb](https://github.com/dveeden/meb-deb) to create a package from an official tarball. * `xtrabackup`: Implements backups with XtraBackup from Percona. Backup type: Physical. ##### `maxallowedpacket` Defines the maximum SQL statement size for the backup dump script. The default value is 1MB, as this is the default MySQL Server value. #### mysql::server::monitor ##### `mysql_monitor_username` The username to create for MySQL monitoring. ##### `mysql_monitor_password` The password to create for MySQL monitoring. ##### `mysql_monitor_hostname` The hostname from which the monitoring user requests are allowed access. #### mysql::server::mysqltuner **Note**: If you're using this class on a non-network-connected system, you must download the mysqltuner.pl script and have it hosted somewhere accessible via `http(s)://`, `puppet://`, `ftp://`, or a fully qualified file path. ##### `ensure` Ensures that the resource exists. Valid values are `present`, `absent`. Defaults to `present`. ##### `version` The version to install from the major/MySQLTuner-perl github repository. Must be a valid tag. Defaults to 'v1.3.0'. ##### `source` Specifies the source. If not specified, defaults to `https://github.com/major/MySQLTuner-perl/raw/${version}/mysqltuner.pl` #### mysql::bindings ##### `client_dev` Specifies whether `::mysql::bindings::client_dev` should be included. Valid values are true', false. Defaults to false. ##### `daemon_dev` Specifies whether `::mysql::bindings::daemon_dev` should be included. Valid values are true, false. Defaults to false. ##### `java_enable` Specifies whether `::mysql::bindings::java` should be included. Valid values are true, false. Defaults to false. ##### `perl_enable` Specifies whether `mysql::bindings::perl` should be included. Valid values are true, false. Defaults to false. ##### `php_enable` Specifies whether `mysql::bindings::php` should be included. Valid values are true, false. Defaults to false. ##### `python_enable` Specifies whether `mysql::bindings::python` should be included. Valid values are true, false. Defaults to false. ##### `ruby_enable` Specifies whether `mysql::bindings::ruby` should be included. Valid values are true, false. Defaults to false. ##### `install_options` Passes `install_options` array to managed package resources. You must pass the [appropriate options](https://docs.puppetlabs.com/references/latest/type.html#package-attribute-install_options) for the package manager(s). ##### `client_dev_package_ensure` Whether the package should be present, absent, or a specific version. Valid values are 'present', 'absent', or 'x.y.z'. Only applies if `client_dev => true`. ##### `client_dev_package_name` The name of the client_dev package to install. Only applies if `client_dev => true`. ##### `client_dev_package_provider` The provider to use to install the client_dev package. Only applies if `client_dev => true`. ##### `daemon_dev_package_ensure` Whether the package should be present, absent, or a specific version. Valid values are 'present', 'absent', or 'x.y.z'. Only applies if `daemon_dev => true`. ##### `daemon_dev_package_name` The name of the daemon_dev package to install. Only applies if `daemon_dev => true`. ##### `daemon_dev_package_provider` The provider to use to install the daemon_dev package. Only applies if `daemon_dev => true`. ##### `java_package_ensure` Whether the package should be present, absent, or a specific version. Valid values are 'present', 'absent', or 'x.y.z'. Only applies if `java_enable => true`. ##### `java_package_name` The name of the Java package to install. Only applies if `java_enable => true`. ##### `java_package_provider` The provider to use to install the Java package. Only applies if `java_enable => true`. ##### `perl_package_ensure` Whether the package should be present, absent, or a specific version. Valid values are 'present', 'absent', or 'x.y.z'. Only applies if `perl_enable => true`. ##### `perl_package_name` The name of the Perl package to install. Only applies if `perl_enable => true`. ##### `perl_package_provider` The provider to use to install the Perl package. Only applies if `perl_enable => true`. ##### `php_package_ensure` Whether the package should be present, absent, or a specific version. Valid values are 'present', 'absent', or 'x.y.z'. Only applies if `php_enable => true`. ##### `php_package_name` The name of the PHP package to install. Only applies if `php_enable => true`. ##### `python_package_ensure` Whether the package should be present, absent, or a specific version. Valid values are 'present', 'absent', or 'x.y.z'. Only applies if `python_enable => true`. ##### `python_package_name` The name of the Python package to install. Only applies if `python_enable => true`. ##### `python_package_provider` The provider to use to install the PHP package. Only applies if `python_enable => true`. ##### `ruby_package_ensure` Whether the package should be present, absent, or a specific version. Valid values are 'present', 'absent', or 'x.y.z'. Only applies if `ruby_enable => true`. ##### `ruby_package_name` The name of the Ruby package to install. Only applies if `ruby_enable => true`. ##### `ruby_package_provider` What provider should be used to install the package. #### mysql::client ##### `bindings_enable` Whether to automatically install all bindings. Valid values are true, false. Default to false. ##### `install_options` Array of install options for managed package resources. You must pass the appropriate options for the package manager. ##### `package_ensure` Whether the MySQL package should be present, absent, or a specific version. Valid values are 'present', 'absent', or 'x.y.z'. ##### `package_manage` Whether to manage the MySQL client package. Defaults to true. ##### `package_name` The name of the MySQL client package to install. ### Defines #### mysql::db ``` mysql_database { 'information_schema': ensure => 'present', charset => 'utf8', collate => 'utf8_swedish_ci', } mysql_database { 'mysql': ensure => 'present', charset => 'latin1', collate => 'latin1_swedish_ci', } ``` ##### `user` The user for the database you're creating. ##### `password` The password for $user for the database you're creating. ##### `dbname` The name of the database to create. Defaults to $name. ##### `charset` The character set for the database. Defaults to 'utf8'. ##### `collate` The collation for the database. Defaults to 'utf8_general_ci'. ##### `host` The host to use as part of user@host for grants. Defaults to 'localhost'. ##### `grant` The privileges to be granted for user@host on the database. Defaults to 'ALL'. ##### `sql` The path to the sqlfile you want to execute. This can be single file specified as string, or it can be an array of strings. Defaults to undef. ##### `enforce_sql` Specifies whether executing the sqlfiles should happen on every run. If set to false, sqlfiles only run once. Valid values are true, false. Defaults to false. ##### `ensure` Specifies whether to create the database. Valid values are 'present', 'absent'. Defaults to 'present'. ##### `import_timeout` Timeout, in seconds, for loading the sqlfiles. Defaults to '300'. ##### `import_cat_cmd` Command to read the sqlfile for importing the database. Useful for compressed sqlfiles. For example, you can use 'zcat' for .gz files. Defaults to 'cat'. ### Types #### mysql_database `mysql_database` creates and manages databases within MySQL. ##### `ensure` Whether the resource is present. Valid values are 'present', 'absent'. Defaults to 'present'. ##### `name` The name of the MySQL database to manage. ##### `charset` The CHARACTER SET setting for the database. Defaults to ':utf8'. ##### `collate` The COLLATE setting for the database. Defaults to ':utf8_general_ci'. #### mysql_user Creates and manages user grants within MySQL. ``` mysql_user { 'root@127.0.0.1': ensure => 'present', max_connections_per_hour => '0', max_queries_per_hour => '0', max_updates_per_hour => '0', max_user_connections => '0', } ``` You can also specify an authentication plugin. ``` mysql_user{ 'myuser'@'localhost': ensure => 'present', plugin => 'unix_socket', } ``` TLS options can be specified for a user. ``` mysql_user{ 'myuser'@'localhost': ensure => 'present', tls_options => ['SSL'], } ``` ##### `name` The name of the user, as 'username@hostname' or username@hostname. ##### `password_hash` The user's password hash of the user. Use mysql_password() for creating such a hash. ##### `max_user_connections` Maximum concurrent connections for the user. Must be an integer value. A value of '0' specifies no (or global) limit. ##### `max_connections_per_hour` Maximum connections per hour for the user. Must be an integer value. A value of '0' specifies no (or global) limit. ##### `max_queries_per_hour` Maximum queries per hour for the user. Must be an integer value. A value of '0' specifies no (or global) limit. ##### `max_updates_per_hour` Maximum updates per hour for the user. Must be an integer value. A value of '0' specifies no (or global) limit. ##### `tls_options` SSL-related options for a MySQL account, using one or more tls_option values. 'NONE' specifies that the account has no TLS options enforced, and the available options are 'SSL', 'X509', 'CIPHER *cipher*', 'ISSUER *issuer*', 'SUBJECT *subject*'; as stated in the MySQL documentation. #### mysql_grant `mysql_grant` creates grant permissions to access databases within MySQL. To create grant permissions to access databases with MySQL, use it you must create the title of the resource as shown below, following the pattern of `username@hostname/database.table`: ``` mysql_grant { 'root@localhost/*.*': ensure => 'present', options => ['GRANT'], privileges => ['ALL'], table => '*.*', user => 'root@localhost', } ``` It is possible to specify privileges down to the column level: ``` mysql_grant { 'root@localhost/mysql.user': ensure => 'present', privileges => ['SELECT (Host, User)'], table => 'mysql.user', user => 'root@localhost', } ``` To revoke GRANT privilege specify ['NONE']. ##### `ensure` Whether the resource is present. Valid values are 'present', 'absent'. Defaults to 'present'. ##### `name` Name to describe the grant. Must in a 'user/table' format. ##### `privileges` Privileges to grant the user. ##### `table` The table to which privileges are applied. ##### `user` User to whom privileges are granted. ##### `options` MySQL options to grant. Optional. #### mysql_plugin `mysql_plugin` can be used to load plugins into the MySQL Server. ``` mysql_plugin { 'auth_socket': ensure => 'present', soname => 'auth_socket.so', } ``` ##### `ensure` Whether the resource is present. Valid values are 'present', 'absent'. Defaults to 'present'. ##### `name` The name of the MySQL plugin to manage. ##### `soname` The library file name. #### `mysql_datadir` Initializes the MySQL data directory with version specific code. Pre MySQL 5.7.6 it uses mysql_install_db. After MySQL 5.7.6 it uses mysqld --initialize-insecure. Insecure initialization is needed, as mysqld version 5.7 introduced "secure by default" mode. This means MySQL generates a random password and writes it to STDOUT. This means puppet can never accesss the database server afterwards, as no credencials are available. This type is an internal type and should not be called directly. ### Facts #### `mysql_version` Determines the MySQL version by parsing the output from `mysql --version` #### `mysql_server_id` Generates a unique id, based on the node's MAC address, which can be used as `server_id`. This fact will *always* return `0` on nodes that have only loopback interfaces. Because those nodes aren't connected to the outside world, this shouldn't cause any conflicts. ## Limitations This module has been tested on: * RedHat Enterprise Linux 5, 6, 7 * Debian 6, 7, 8 * CentOS 5, 6, 7 * Ubuntu 10.04, 12.04, 14.04, 16.04 * Scientific Linux 5, 6 * SLES 11 Testing on other platforms has been minimal and cannot be guaranteed. **Note:** The mysqlbackup.sh does not work and is not supported on MySQL 5.7 and greater. ## Development Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can't access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. Check out our the complete [module contribution guide](https://docs.puppetlabs.com/forge/contributing.html). ### Authors This module is based on work by David Schmitt. The following contributors have contributed to this module (beyond Puppet Labs): * Larry Ludwig * Christian G. Warden * Daniel Black * Justin Ellison * Lowe Schmidt * Matthias Pigulla * William Van Hevelingen * Michael Arnold * Chris Weyl * Daniël van Eeden * Jan-Otto Kröpke puppetlabs-mysql-3.10.0/CHANGELOG.md0000644005276200011600000007174613010160216016623 0ustar jenkinsjenkins## Supported Release 3.10.0 ### Summary This release includes new features for setting TLS options on a mysql user, a new parameter to allow specifying tool to import sql files, as well as various bugfixes. #### Features - (MODULES-3879) Adds `import_cat_cmd` parameter to specify the command to read sql files - Adds support for setting `tls_options` in `mysql_user` #### Bugfixes - (MODULES-3557) Adds Ubuntu 16.04 package names for language bindings - (MODULES-3907) Adds MySQL/Percona 5.7 initialize on fresh deploy ## Supported Release 3.9.0 ### Summary This release adds Percona 5.7 support and compatibility with Ubuntu 16.04, in addition to various bugfixes. #### Features - (MODULES-3441) Adds the `mysqld_version` fact - (MODULES-3513) Adds a new backup dump parameter `maxallowedpacket` - Adds new parameter `xtrabackup_package_name` to `mysql::backup::xtrabackup` class - Adds ability to revoke GRANT privilege #### Bugfixes - Fixes a bug where `mysql_user` fails if facter cannot retrieve fqdn. - Fix global parameter usage in backup script - Adds support for `puppet-staging` version `2.0.0` - (MODULES-3601) Moves binary logging configuration to take place after package install - (MODULES-3711) Add limit to mysql server ID generated value - (MODULES-3698) Fixes defaults for SLES12 - Updates user name length restrictions for MySQL version 5.7.8 and above. - Fixes a bug where error log is not writable by owner ## Supported Release 3.8.0 ###Summary This release adds Percona 5.7 support and compatibility with Ubuntu 16.04, in addition to various bugfixes. #### Features - Adds support for Percona 5.7 - Adds support for Ubuntu 16.04 (Xenial) #### Known Limitations - The mysqlbackup.sh script will not work on MySQL 5.7.0 and up. #### Bugfixes - Use mysql_install_db only with uniq defaults-extra-file - Updates mysqlbackup.sh to ensure backup directory exist - Loosen MariaDB recognition to fix it on Debian 8 - Allow mysql::backup::mysqldump to access root_group in tests - Fixed problem with ignoring parameters from global configs - Fixes ordering issue that initialized mysqld before config is set - (MODULES-1256) Fix parameters on OpenSUSE 12 - Fixes install errors on Debian-based OS by configuring the base of includedir - Configure the configfile location for mariadb - Default mysqld_type return value should be 'mysql' if another type is not detected - Make sure that bzip2 is installed before setting up the cron tab job using mysqlbackup.sh - Fixes path issue on FreeBSD - Check that /var/lib/mysql actually contains files - Removes mysql regex when checking type - (MODULES-2111) Add the system database to user related actions - Updates default group for logfiles on Debian-based OS to 'adm' - Fixes an issue with Amazon linux major release 4 installation - Fixes 'mysql_install_db' script support on Gentoo - Removes erroneous anchors to mysql::client from mysql::db - Adds path to be able to find MySQL 5.5 installation on CentOS ## Supported Release 3.7.0 ###Summary A large release with several new features. Also includes a considerable amount of bugfixes, many around compatibility and improvements to current functionality. #### Features - Now uses mariadb in OpenSuSE >= 13.1. - Switch to rspec-puppet-facts. - Additional function to check if table exists before grant. - Add ability to input password hash directly. - Now checking major release instead of specific release. - Debian 8 support. #### Bugfixes - Minor doc update. - Fixes improper use of function `warn` in backup manifest of server. - Fixes to Compatibility with PE 3.3. - Fixes `when not managing config file` in `mysql_server_spec`. - Improved user validation and munging. - Fixes fetching the mysql_user password for MySQL >=5.7.6. - Fixes unique server_id within my.cnf, the issue were the entire mac address was not being read in to generate the id. - Corrects the daemon_dev_package_name for mariadb on redhat. - Fix version compare to properly suppress show_diff for root password. - Fixes to ensure compatibility with future parser. - Solaris removed from PE in metadata as its not supported. - Use MYSQL_PWD to avoid mysqldump warnings. - Use temp cnf file instead of env variable which creates acceptance test failures. - No longer hash passwords that are already hashed. - Fix Gemfile to work with ruby 1.8.7. - Fixed MySQL 5.7.6++ compatibility. - Fixing error when disabling service management and the service does not exist. - Ubuntu vivid should use systemd not upstart. - Fixed new mysql_datadir provider on CentOS for MySQl 5.7.6 compatibility. - Ensure if service restart to wait till mysql is up. - Move all dependencies to not have them in case of service unmanaged. - Re-Added the ability to set a empty string as option parameter. - Fixes edge-case with dropping pre-existing users with grants. - Fix logic for choosing rspec version. - Refactored main acceptance suite. - Skip idempotency tests on test cells that do have PUP-5016 unfixed. - Fix tmpdir to be shared across examples. - Update to current msync configs [006831f]. - Fix mysql_grant with MySQL ANSI_QUOTES mode. - Generate .my.cnf for all sections. ## Supported Release 3.6.2 ###Summary Small release for support of newer PE versions. This increments the version of PE in the metadata.json file. ## 2015-09-22 - Supported Release 3.6.1 ### Summary This is a security and bugfix release that fixes incorrect username truncation in the munge for the mysql_user type, incorrect function used in `mysql::server::backup` and fixes compatibility issues with PE 3.3.x. #### Bugfixes - Loosen the regex in mysql_user munging so the username is not unintentionally truncated. - Use `warning()` not `warn()` - Metadata had inadvertantly dropped 3.3.x support - Some 3.3.x compatibility issues in `mysqltuner` were corrected ## 2015-08-10 - Supported Release 3.6.0 ### Summary This release adds the ability to use mysql::db and `mysql_*` types against unmanaged or external mysql instances. #### Features - Add ability to use mysql::db WITHOUT mysql::server (ie, externally) - Add prescript attribute to mysql::server::backup for xtrabackup - Add postscript ability to xtrabackup provider. #### Bugfixes - Fix default root passwords blocking puppet on mysql 5.8 - Fix service dependency when package_manage is false - Fix selinux permissions on my.cnf ##2015-07-23 - Supported Release 3.5.0 ###Summary A small release to add explicit support to newer Puppet versions and accumulated patches. ####Features/Improvements - Start running tests against puppet 4 - Support longer usernames on newer MariaDB versions - Add parameters for Solaris 11 and 12 ####Bugfixes - Fix references to the mysql-server package - mysql_server_id doesn't throw and error on machines without macaddress ##2015-05-19 - Supported Release 3.4.0 ###Summary This release includes the addition of extra facts, OpenBSD compatibility, and a number of other features, improvements and bug fixes. ####Features/Improvements - Added server_id fact which includes mac address for better uniqueness - Added OpenBSD compatibility, only for 'OpenBSD -current' (due to the recent switch to mariadb) - Added a $mysql_group parameter, and use that instead of the $root_group parameter to define the group membership of the mysql error log file. - Updated tests for rspec-puppet 2 and future parser - Further acceptance testing improvements - MODULES-1928 - allow log-error to be undef - Split package installation and database install - README wording improvements - Added options for including/excluding triggers and routines - Made the 'TRIGGER' privilege of mysqldump backups depend on whether or not we are actually backing up triggers - Cleaned up the privilege assignment in the mysqldump backup script - Add a fact for capturing the mysql version installed ####Bugfixes - mysql backup: fix regression in mysql_user call - Set service_ensure to undef, in the case of an unmanaged service - README Typos fixed - Bugfix on Xtrabackup crons - Fixed a permission problem that was preventing triggers from being backed up - MODULES-1981: Revoke and grant difference of old and new privileges - Fix an issue were we assume triggers work - Change default for mysql::server::backup to ignore_triggers = false ####Deprecations mysql::server::old_root_password property ##2015-03-03 - Supported Release 3.3.0 ###Summary This release includes major README updates, the addition of backup providers, and a fix for managing the log-bin directory. ####Features - Add package_manage parameters to `mysql::server` and `mysql::client` (MODULES-1143) - README improvements - Add `mysqldump`, `mysqlbackup`, and `xtrabackup` backup providers. ####Bugfixes - log-error overrides were not being properly used (MODULES-1804) - check for full path for log-bin to stop puppet from managing file '.' ##2015-02-09 - Supported Release 3.2.0 ###Summary This release includes several new features and bugfixes, including support for various plugins, making the output from mysql_password more consistent when input is empty and improved username validation. ####Features - Add type and provider to manage plugins - Add support for authentication plugins - Add support for mysql_install_db on freebsd - Add `create_root_user` and `create_root_my_cnf` parameters to `mysql::server` ####Bugfixes - Remove dependency on stdlib >= 4.1.0 (MODULES-1759) - Make grant autorequire user - Remove invalid parameter 'provider' from mysql_user instance (MODULES-1731) - Return empty string for empty input in mysql_password - Fix `mysql::account_security` when fqdn==localhost - Update username validation (MODULES-1520) - Future parser fix in params.pp - Fix package name for debian 8 - Don't start the service until the server package is installed and the config file is in place - Test fixes - Lint fixes ##2014-12-16 - Supported Release 3.1.0 ###Summary This release includes several new features, including SLES12 support, and a number of bug fixes. ####Notes `mysql::server::mysqltuner` has been refactored to fetch the mysqltuner script from github by default. If you are running on a non-network-connected system, you will need to download that file and have it available to your node at a path specified by the `source` parameter to the `mysqltuner` class. ####Features - Add support for install_options for all package resources (MODULES-1484) - Add log-bin directory creation - Allow mysql::db to import multiple files (MODULES-1338) - SLES12 support - Improved identifier quoting detections - Reworked `mysql::server::mysqltuner` so that we are no longer packaging the script as it is licensed under the GPL. ####Bugfixes - Fix regression in username validation - Proper containment for mysql::client in mysql::db - Support quoted usernames of length 15 and 16 chars ##2014-11-11 - Supported Release 3.0.0 ###Summary Added several new features including MariaDB support and future parser ####Backwards-incompatible Changes * Remove the deprecated `database`, `database_user`, and `database_grant` resources. The correct resources to use are `mysql`, `mysql_user`, and `mysql_grant` respectively. ####Features * Add MariaDB Support * The mysqltuner perl script has been updated to 1.3.0 based on work at http://github.com/major/MySQLTuner-perl * Add future parse support, fixed issues with undef to empty string * Pass the backup credentials to 'SHOW DATABASES' * Ability to specify the Includedir for `mysql::server` * `mysql::db` now has an import\_timeout feature that defaults to 300 * The `mysql` class has been removed * `mysql::server` now takes an `override_options` hash that will affect the installation * Ability to install both dev and client dev ####BugFix * `mysql::server::backup` now passes `ensure` param to the nested `mysql_grant` * `mysql::server::service` now properly requires the presence of the `log_error` file * `mysql::config` now occurs before `mysql::server::install_db` correctly ##2014-07-15 - Supported Release 2.3.1 ###Summary This release merely updates metadata.json so the module can be uninstalled and upgraded via the puppet module command. ##2014-05-14 - Supported Release 2.3.0 This release primarily adds support for RHEL7 and Ubuntu 14.04 but it also adds a couple of new parameters to allow for further customization, as well as ensuring backups can backup stored procedures properly. ####Features Added `execpath` to allow a custom executable path for non-standard mysql installations. Added `dbname` to mysql::db and use ensure_resource to create the resource. Added support for RHEL7 and Fedora Rawhide. Added support for Ubuntu 14.04. Create a warning for if you disable SSL. Ensure the error logfile is owned by MySQL. Disable ssl on FreeBSD. Add PROCESS privilege for backups. ####Bugfixes ####Known Bugs * No known bugs ##2014-03-04 - Supported Release 2.2.3 ###Summary This is a supported release. This release removes a testing symlink that can cause trouble on systems where /var is on a seperate filesystem from the modulepath. ####Features ####Bugfixes ####Known Bugs * No known bugs ##2014-03-04 - Supported Release 2.2.2 ###Summary This is a supported release. Mostly comprised of enhanced testing, plus a bugfix for Suse. ####Bugfixes - PHP bindings on Suse - Test fixes ####Known Bugs * No known bugs ##2014-02-19 - Version 2.2.1 ###Summary Minor release that repairs mysql_database{} so that it sees the correct collation settings (it was only checking the global mysql ones, not the actual database and constantly setting it over and over since January 22nd). Also fixes a bunch of tests on various platforms. ##2014-02-13 - Version 2.2.0 ###Summary ####Features - Add `backupdirmode`, `backupdirowner`, `backupdirgroup` to mysql::server::backup to allow customizing the mysqlbackupdir. - Support multiple options of the same name, allowing you to do 'replicate-do-db' => ['base1', 'base2', 'base3'] in order to get three lines of replicate-do-db = base1, replicate-do-db = base2 etc. ####Bugfixes - Fix `restart` so it actually stops mysql restarting if set to false. - DRY out the defaults_file functionality in the providers. - mysql_grant fixed to work with root@localhost/@. - mysql_grant fixed for WITH MAX_QUERIES_PER_HOUR - mysql_grant fixed so revoking all privileges accounts for GRANT OPTION - mysql_grant fixed to remove duplicate privileges. - mysql_grant fixed to handle PROCEDURES when removing privileges. - mysql_database won't try to create existing databases, breaking replication. - bind_address renamed bind-address in 'mysqld' options. - key_buffer renamed to key_buffer_size. - log_error renamed to log-error. - pid_file renamed to pid-file. - Ensure mysql::server:root_password runs before mysql::server::backup - Fix options_override -> override_options in the README. - Extensively rewrite the README to be accurate and awesome. - Move to requiring stdlib 3.2.0, shipped in PE3.0 - Add many new tests. ##2013-11-13 - Version 2.1.0 ###Summary The most important changes in 2.1.0 are improvements to the my.cnf creation, as well as providers. Setting options to = true strips them to be just the key name itself, which is required for some options. The provider updates fix a number of bugs, from lowercase privileges to deprecation warnings. Last, the new hiera integration functionality should make it easier to externalize all your grants, users, and, databases. Another great set of community submissions helped to make this release. ####Features - Some options can not take a argument. Gets rid of the '= true' when an option is set to true. - Easier hiera integration: Add hash parameters to mysql::server to allow specifying grants, users, and databases. ####Bugfixes - Fix an issue with lowercase privileges in mysql_grant{} causing them to be reapplied needlessly. - Changed defaults-file to defaults-extra-file in providers. - Ensure /root/.my.cnf is 0600 and root owned. - database_user deprecation warning was incorrect. - Add anchor pattern for client.pp - Documentation improvements. - Various test fixes. ##2013-10-21 - Version 2.0.1 ###Summary This is a bugfix release to handle an issue where unsorted mysql_grant{} privileges could cause Puppet to incorrectly reapply the permissions on each run. ####Bugfixes - Mysql_grant now sorts privileges in the type and provider for comparison. - Comment and test tweak for PE3.1. ##2013-10-14 - Version 2.0.0 ###Summary (Previously detailed in the changelog for 2.0.0-rc1) This module has been completely refactored and works significantly different. The changes are broad and touch almost every piece of the module. See the README.md for full details of all changes and syntax. Please remain on 1.0.0 if you don't have time to fully test this in dev. * mysql::server, mysql::client, and mysql::bindings are the primary interface classes. * mysql::server takes an `override_options` parameter to set my.cnf options, with the hash format: { 'section' => { 'thing' => 'value' }} * mysql attempts backwards compatibility by forwarding all parameters to mysql::server. ##2013-10-09 - Version 2.0.0-rc5 ###Summary Hopefully the final rc! Further fixes to mysql_grant (stripping out the cleverness so we match a much wider range of input.) ####Bugfixes - Make mysql_grant accept '.*'@'.*' in terms of input for user@host. ##2013-10-09 - Version 2.0.0-rc4 ###Summary Bugfixes to mysql_grant and mysql_user form the bulk of this rc, as well as ensuring that values in the override_options hash that contain a value of '' are created as just "key" in the conf rather than "key =" or "key = false". ####Bugfixes - Improve mysql_grant to work with IPv6 addresses (both long and short). - Ensure @host users work as well as user@host users. - Updated my.cnf template to support items with no values. ##2013-10-07 - Version 2.0.0-rc3 ###Summary Fix mysql::server::monitor's use of mysql_user{}. ####Bugfixes - Fix myql::server::monitor's use of mysql_user{} to grant the proper permissions. Add specs as well. (Thanks to treydock!) ##2013-10-03 - Version 2.0.0-rc2 ###Summary Bugfixes ####Bugfixes - Fix a duplicate parameter in mysql::server ##2013-10-03 - Version 2.0.0-rc1 ###Summary This module has been completely refactored and works significantly different. The changes are broad and touch almost every piece of the module. See the README.md for full details of all changes and syntax. Please remain on 1.0.0 if you don't have time to fully test this in dev. * mysql::server, mysql::client, and mysql::bindings are the primary interface classes. * mysql::server takes an `override_options` parameter to set my.cnf options, with the hash format: { 'section' => { 'thing' => 'value' }} * mysql attempts backwards compatibility by forwarding all parameters to mysql::server. --- ##2013-09-23 - Version 1.0.0 ###Summary This release introduces a number of new type/providers, to eventually replace the database_ ones. The module has been converted to call the new providers rather than the previous ones as they have a number of fixes, additional options, and work with puppet resource. This 1.0.0 release precedes a large refactoring that will be released almost immediately after as 2.0.0. ####Features - Added mysql_grant, mysql_database, and mysql_user. - Add `mysql::bindings` class and refactor all other bindings to be contained underneath mysql::bindings:: namespace. - Added support to back up specified databases only with 'mysqlbackup' parameter. - Add option to mysql::backup to set the backup script to perform a mysqldump on each database to its own file ####Bugfixes - Update my.cnf.pass.erb to allow custom socket support - Add environment variable for .my.cnf in mysql::db. - Add HOME environment variable for .my.cnf to mysqladmin command when (re)setting root password --- ##2013-07-15 - Version 0.9.0 ####Features - Add `mysql::backup::backuprotate` parameter - Add `mysql::backup::delete_before_dump` parameter - Add `max_user_connections` attribute to `database_user` type ####Bugfixes - Add client package dependency for `mysql::db` - Remove duplicate `expire_logs_days` and `max_binlog_size` settings - Make root's `.my.cnf` file path dynamic - Update pidfile path for Suse variants - Fixes for lint ##2013-07-05 - Version 0.8.1 ####Bugfixes - Fix a typo in the Fedora 19 support. ##2013-07-01 - Version 0.8.0 ####Features - mysql::perl class to install perl-DBD-mysql. - minor improvements to the providers to improve reliability - Install the MariaDB packages on Fedora 19 instead of MySQL. - Add new `mysql` class parameters: - `max_connections`: The maximum number of allowed connections. - `manage_config_file`: Opt out of puppetized control of my.cnf. - `ft_min_word_len`: Fine tune the full text search. - `ft_max_word_len`: Fine tune the full text search. - Add new `mysql` class performance tuning parameters: - `key_buffer` - `thread_stack` - `thread_cache_size` - `myisam-recover` - `query_cache_limit` - `query_cache_size` - `max_connections` - `tmp_table_size` - `table_open_cache` - `long_query_time` - Add new `mysql` class replication parameters: - `server_id` - `sql_log_bin` - `log_bin` - `max_binlog_size` - `binlog_do_db` - `expire_logs_days` - `log_bin_trust_function_creators` - `replicate_ignore_table` - `replicate_wild_do_table` - `replicate_wild_ignore_table` - `expire_logs_days` - `max_binlog_size` ####Bugfixes - No longer restart MySQL when /root/.my.cnf changes. - Ensure mysql::config runs before any mysql::db defines. ##2013-06-26 - Version 0.7.1 ####Bugfixes - Single-quote password for special characters - Update travis testing for puppet 3.2.x and missing Bundler gems ##2013-06-25 - Version 0.7.0 This is a maintenance release for community bugfixes and exposing configuration variables. * Add new `mysql` class parameters: - `basedir`: The base directory mysql uses - `bind_address`: The IP mysql binds to - `client_package_name`: The name of the mysql client package - `config_file`: The location of the server config file - `config_template`: The template to use to generate my.cnf - `datadir`: The directory MySQL's datafiles are stored - `default_engine`: The default engine to use for tables - `etc_root_password`: Whether or not to add the mysql root password to /etc/my.cnf - `java_package_name`: The name of the java package containing the java connector - `log_error`: Where to log errors - `manage_service`: Boolean dictating if mysql::server should manage the service - `max_allowed_packet`: Maximum network packet size mysqld will accept - `old_root_password`: Previous root user password - `php_package_name`: The name of the phpmysql package to install - `pidfile`: The location mysql will expect the pidfile to be - `port`: The port mysql listens on - `purge_conf_dir`: Value fed to recurse and purge parameters of the /etc/mysql/conf.d resource - `python_package_name`: The name of the python mysql package to install - `restart`: Whether to restart mysqld - `root_group`: Use specified group for root-owned files - `root_password`: The root MySQL password to use - `ruby_package_name`: The name of the ruby mysql package to install - `ruby_package_provider`: The installation suite to use when installing the ruby package - `server_package_name`: The name of the server package to install - `service_name`: The name of the service to start - `service_provider`: The name of the service provider - `socket`: The location of the MySQL server socket file - `ssl_ca`: The location of the SSL CA Cert - `ssl_cert`: The location of the SSL Certificate to use - `ssl_key`: The SSL key to use - `ssl`: Whether or not to enable ssl - `tmpdir`: The directory MySQL's tmpfiles are stored * Deprecate `mysql::package_name` parameter in favor of `mysql::client_package_name` * Fix local variable template deprecation * Fix dependency ordering in `mysql::db` * Fix ANSI quoting in queries * Fix travis support (but still messy) * Fix typos ##2013-01-11 - Version 0.6.1 * Fix providers when /root/.my.cnf is absent ##2013-01-09 - Version 0.6.0 * Add `mysql::server::config` define for specific config directives * Add `mysql::php` class for php support * Add `backupcompress` parameter to `mysql::backup` * Add `restart` parameter to `mysql::config` * Add `purge_conf_dir` parameter to `mysql::config` * Add `manage_service` parameter to `mysql::server` * Add syslog logging support via the `log_error` parameter * Add initial SuSE support * Fix remove non-localhost root user when fqdn != hostname * Fix dependency in `mysql::server::monitor` * Fix .my.cnf path for root user and root password * Fix ipv6 support for users * Fix / update various spec tests * Fix typos * Fix lint warnings ##2012-08-23 - Version 0.5.0 * Add puppetlabs/stdlib as requirement * Add validation for mysql privs in provider * Add `pidfile` parameter to mysql::config * Add `ensure` parameter to mysql::db * Add Amazon linux support * Change `bind_address` parameter to be optional in my.cnf template * Fix quoting root passwords ##2012-07-24 - Version 0.4.0 * Fix various bugs regarding database names * FreeBSD support * Allow specifying the storage engine * Add a backup class * Add a security class to purge default accounts ##2012-05-03 - Version 0.3.0 * 14218 Query the database for available privileges * Add mysql::java class for java connector installation * Use correct error log location on different distros * Fix set_mysql_rootpw to properly depend on my.cnf ##2012-04-11 - Version 0.2.0 ##2012-03-19 - William Van Hevelingen * (#13203) Add ssl support (f7e0ea5) ##2012-03-18 - Nan Liu * Travis ci before script needs success exit code. (0ea463b) ##2012-03-18 - Nan Liu * Fix Puppet 2.6 compilation issues. (9ebbbc4) ##2012-03-16 - Nan Liu * Add travis.ci for testing multiple puppet versions. (33c72ef) ##2012-03-15 - William Van Hevelingen * (#13163) Datadir should be configurable (f353fc6) ##2012-03-16 - Nan Liu * Document create_resources dependency. (558a59c) ##2012-03-16 - Nan Liu * Fix spec test issues related to error message. (eff79b5) ##2012-03-16 - Nan Liu * Fix mysql service on Ubuntu. (72da2c5) ##2012-03-16 - Dan Bode * Add more spec test coverage (55e399d) ##2012-03-16 - Nan Liu * (#11963) Fix spec test due to path changes. (1700349) ##2012-03-07 - François Charlier * Add a test to check path for 'mysqld-restart' (b14c7d1) ##2012-03-07 - François Charlier * Fix path for 'mysqld-restart' (1a9ae6b) ##2012-03-15 - Dan Bode * Add rspec-puppet tests for mysql::config (907331a) ##2012-03-15 - Dan Bode * Moved class dependency between sever and config to server (da62ad6) ##2012-03-14 - Dan Bode * Notify mysql restart from set_mysql_rootpw exec (0832a2c) ##2012-03-15 - Nan Liu * Add documentation related to osfamily fact. (8265d28) ##2012-03-14 - Dan Bode * Mention osfamily value in failure message (e472d3b) ##2012-03-14 - Dan Bode * Fix bug when querying for all database users (015490c) ##2012-02-09 - Nan Liu * Major refactor of mysql module. (b1f90fd) ##2012-01-11 - Justin Ellison * Ruby and Python's MySQL libraries are named differently on different distros. (1e926b4) ##2012-01-11 - Justin Ellison * Per @ghoneycutt, we should fail explicitly and explain why. (09af083) ##2012-01-11 - Justin Ellison * Removing duplicate declaration (7513d03) ##2012-01-10 - Justin Ellison * Use socket value from params class instead of hardcoding. (663e97c) ##2012-01-10 - Justin Ellison * Instead of hardcoding the config file target, pull it from mysql::params (031a47d) ##2012-01-10 - Justin Ellison * Moved $socket to within the case to toggle between distros. Added a $config_file variable to allow per-distro config file destinations. (360eacd) ##2012-01-10 - Justin Ellison * Pretty sure this is a bug, 99% of Linux distros out there won't ever hit the default. (3462e6b) ##2012-02-09 - William Van Hevelingen * Changed the README to use markdown (3b7dfeb) ##2012-02-04 - Daniel Black * (#12412) mysqltuner.pl update (b809e6f) ##2011-11-17 - Matthias Pigulla * (#11363) Add two missing privileges to grant: event_priv, trigger_priv (d15c9d1) ##2011-12-20 - Jeff McCune * (minor) Fixup typos in Modulefile metadata (a0ed6a1) ##2011-12-19 - Carl Caum * Only notify Exec to import sql if sql is given (0783c74) ##2011-12-19 - Carl Caum * (#11508) Only load sql_scripts on DB creation (e3b9fd9) ##2011-12-13 - Justin Ellison * Require not needed due to implicit dependencies (3058feb) ##2011-12-13 - Justin Ellison * Bug #11375: puppetlabs-mysql fails on CentOS/RHEL (a557b8d) ##2011-06-03 - Dan Bode - 0.0.1 * initial commit puppetlabs-mysql-3.10.0/manifests/0000755005276200011600000000000013010160602016763 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/manifests/bindings/0000755005276200011600000000000013010160602020560 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/manifests/bindings/java.pp0000644005276200011600000000051612746170223022063 0ustar jenkinsjenkins# Private class class mysql::bindings::java { package { 'mysql-connector-java': ensure => $mysql::bindings::java_package_ensure, install_options => $mysql::bindings::install_options, name => $mysql::bindings::java_package_name, provider => $mysql::bindings::java_package_provider, } } puppetlabs-mysql-3.10.0/manifests/bindings/php.pp0000644005276200011600000000051612746170223021731 0ustar jenkinsjenkins# Private class: See README.md class mysql::bindings::php { package { 'php-mysql': ensure => $mysql::bindings::php_package_ensure, install_options => $mysql::bindings::install_options, name => $mysql::bindings::php_package_name, provider => $mysql::bindings::php_package_provider, } } puppetlabs-mysql-3.10.0/manifests/bindings/perl.pp0000644005276200011600000000050312746170223022100 0ustar jenkinsjenkins# Private class class mysql::bindings::perl { package{ 'perl_mysql': ensure => $mysql::bindings::perl_package_ensure, install_options => $mysql::bindings::install_options, name => $mysql::bindings::perl_package_name, provider => $mysql::bindings::perl_package_provider, } } puppetlabs-mysql-3.10.0/manifests/bindings/ruby.pp0000644005276200011600000000050312746170223022117 0ustar jenkinsjenkins# Private class class mysql::bindings::ruby { package{ 'ruby_mysql': ensure => $mysql::bindings::ruby_package_ensure, install_options => $mysql::bindings::install_options, name => $mysql::bindings::ruby_package_name, provider => $mysql::bindings::ruby_package_provider, } } puppetlabs-mysql-3.10.0/manifests/bindings/daemon_dev.pp0000644005276200011600000000100612746170223023236 0ustar jenkinsjenkins# Private class class mysql::bindings::daemon_dev { if $mysql::bindings::daemon_dev_package_name { package { 'mysql-daemon_dev': ensure => $mysql::bindings::daemon_dev_package_ensure, install_options => $mysql::bindings::install_options, name => $mysql::bindings::daemon_dev_package_name, provider => $mysql::bindings::daemon_dev_package_provider, } } else { warning("No MySQL daemon development package configured for ${::operatingsystem}.") } } puppetlabs-mysql-3.10.0/manifests/bindings/client_dev.pp0000644005276200011600000000100612746170223023251 0ustar jenkinsjenkins# Private class class mysql::bindings::client_dev { if $mysql::bindings::client_dev_package_name { package { 'mysql-client_dev': ensure => $mysql::bindings::client_dev_package_ensure, install_options => $mysql::bindings::install_options, name => $mysql::bindings::client_dev_package_name, provider => $mysql::bindings::client_dev_package_provider, } } else { warning("No MySQL client development package configured for ${::operatingsystem}.") } } puppetlabs-mysql-3.10.0/manifests/bindings/python.pp0000644005276200011600000000052012746170223022456 0ustar jenkinsjenkins# Private class class mysql::bindings::python { package { 'python-mysqldb': ensure => $mysql::bindings::python_package_ensure, install_options => $mysql::bindings::install_options, name => $mysql::bindings::python_package_name, provider => $mysql::bindings::python_package_provider, } } puppetlabs-mysql-3.10.0/manifests/bindings.pp0000644005276200011600000000576512746170223021155 0ustar jenkinsjenkins# See README.md. class mysql::bindings ( $install_options = undef, # Boolean to determine if we should include the classes. $java_enable = false, $perl_enable = false, $php_enable = false, $python_enable = false, $ruby_enable = false, $client_dev = false, $daemon_dev = false, # Settings for the various classes. $java_package_ensure = $mysql::params::java_package_ensure, $java_package_name = $mysql::params::java_package_name, $java_package_provider = $mysql::params::java_package_provider, $perl_package_ensure = $mysql::params::perl_package_ensure, $perl_package_name = $mysql::params::perl_package_name, $perl_package_provider = $mysql::params::perl_package_provider, $php_package_ensure = $mysql::params::php_package_ensure, $php_package_name = $mysql::params::php_package_name, $php_package_provider = $mysql::params::php_package_provider, $python_package_ensure = $mysql::params::python_package_ensure, $python_package_name = $mysql::params::python_package_name, $python_package_provider = $mysql::params::python_package_provider, $ruby_package_ensure = $mysql::params::ruby_package_ensure, $ruby_package_name = $mysql::params::ruby_package_name, $ruby_package_provider = $mysql::params::ruby_package_provider, $client_dev_package_ensure = $mysql::params::client_dev_package_ensure, $client_dev_package_name = $mysql::params::client_dev_package_name, $client_dev_package_provider = $mysql::params::client_dev_package_provider, $daemon_dev_package_ensure = $mysql::params::daemon_dev_package_ensure, $daemon_dev_package_name = $mysql::params::daemon_dev_package_name, $daemon_dev_package_provider = $mysql::params::daemon_dev_package_provider ) inherits mysql::params { case $::osfamily { 'Archlinux': { if $java_enable { fail("::mysql::bindings::java cannot be managed by puppet on ${::osfamily} as it is not in official repositories. Please disable java mysql binding.") } if $perl_enable { include '::mysql::bindings::perl' } if $php_enable { warning("::mysql::bindings::php does not need to be managed by puppet on ${::osfamily} as it is included in mysql package by default.") } if $python_enable { include '::mysql::bindings::python' } if $ruby_enable { fail("::mysql::bindings::ruby cannot be managed by puppet on ${::osfamily} as it is not in official repositories. Please disable ruby mysql binding.") } } default: { if $java_enable { include '::mysql::bindings::java' } if $perl_enable { include '::mysql::bindings::perl' } if $php_enable { include '::mysql::bindings::php' } if $python_enable { include '::mysql::bindings::python' } if $ruby_enable { include '::mysql::bindings::ruby' } } } if $client_dev { include '::mysql::bindings::client_dev' } if $daemon_dev { include '::mysql::bindings::daemon_dev' } } puppetlabs-mysql-3.10.0/manifests/client/0000755005276200011600000000000013010160602020241 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/manifests/client/install.pp0000644005276200011600000000045612746170223022274 0ustar jenkinsjenkins# See README.md. class mysql::client::install { if $mysql::client::package_manage { package { 'mysql_client': ensure => $mysql::client::package_ensure, install_options => $mysql::client::install_options, name => $mysql::client::package_name, } } } puppetlabs-mysql-3.10.0/manifests/params.pp0000644005276200011600000004204213010160217020613 0ustar jenkinsjenkins# Private class: See README.md. class mysql::params { $manage_config_file = true $purge_conf_dir = false $restart = false $root_password = 'UNSET' $install_secret_file = '/.mysql_secret' $server_package_ensure = 'present' $server_package_manage = true $server_service_manage = true $server_service_enabled = true $client_package_ensure = 'present' $client_package_manage = true $create_root_user = true $create_root_my_cnf = true # mysql::bindings $bindings_enable = false $java_package_ensure = 'present' $java_package_provider = undef $perl_package_ensure = 'present' $perl_package_provider = undef $php_package_ensure = 'present' $php_package_provider = undef $python_package_ensure = 'present' $python_package_provider = undef $ruby_package_ensure = 'present' $ruby_package_provider = undef $client_dev_package_ensure = 'present' $client_dev_package_provider = undef $daemon_dev_package_ensure = 'present' $daemon_dev_package_provider = undef $xtrabackup_package_name = 'percona-xtrabackup' case $::osfamily { 'RedHat': { case $::operatingsystem { 'Fedora': { if versioncmp($::operatingsystemrelease, '19') >= 0 or $::operatingsystemrelease == 'Rawhide' { $provider = 'mariadb' } else { $provider = 'mysql' } } /^(RedHat|CentOS|Scientific|OracleLinux)$/: { if versioncmp($::operatingsystemmajrelease, '7') >= 0 { $provider = 'mariadb' } else { $provider = 'mysql' } } default: { $provider = 'mysql' } } if $provider == 'mariadb' { $client_package_name = 'mariadb' $server_package_name = 'mariadb-server' $server_service_name = 'mariadb' $log_error = '/var/log/mariadb/mariadb.log' $config_file = '/etc/my.cnf.d/server.cnf' # mariadb package by default has !includedir set in my.cnf to /etc/my.cnf.d $includedir = undef $pidfile = '/var/run/mariadb/mariadb.pid' $daemon_dev_package_name = 'mariadb-devel' } else { $client_package_name = 'mysql' $server_package_name = 'mysql-server' $server_service_name = 'mysqld' $log_error = '/var/log/mysqld.log' $config_file = '/etc/my.cnf' $includedir = '/etc/my.cnf.d' $pidfile = '/var/run/mysqld/mysqld.pid' $daemon_dev_package_name = 'mysql-devel' } $basedir = '/usr' $datadir = '/var/lib/mysql' $root_group = 'root' $mysql_group = 'mysql' $socket = '/var/lib/mysql/mysql.sock' $ssl_ca = '/etc/mysql/cacert.pem' $ssl_cert = '/etc/mysql/server-cert.pem' $ssl_key = '/etc/mysql/server-key.pem' $tmpdir = '/tmp' # mysql::bindings $java_package_name = 'mysql-connector-java' $perl_package_name = 'perl-DBD-MySQL' $php_package_name = 'php-mysql' $python_package_name = 'MySQL-python' $ruby_package_name = 'ruby-mysql' $client_dev_package_name = undef } 'Suse': { case $::operatingsystem { 'OpenSuSE': { if versioncmp( $::operatingsystemmajrelease, '12' ) >= 0 { $client_package_name = 'mariadb-client' $server_package_name = 'mariadb' # First service start fails if this is set. Runs fine without # it being set, in any case. Leaving it as-is for the mysql. $basedir = undef } else { $client_package_name = 'mysql-community-server-client' $server_package_name = 'mysql-community-server' $basedir = '/usr' } } 'SLES','SLED': { if versioncmp($::operatingsystemrelease, '12') >= 0 { $client_package_name = 'mariadb-client' $server_package_name = 'mariadb' $basedir = undef } else { $client_package_name = 'mysql-client' $server_package_name = 'mysql' $basedir = '/usr' } } default: { fail("Unsupported platform: puppetlabs-${module_name} currently doesn't support ${::operatingsystem}") } } $config_file = '/etc/my.cnf' $includedir = '/etc/my.cnf.d' $datadir = '/var/lib/mysql' $log_error = $::operatingsystem ? { /OpenSuSE/ => '/var/log/mysql/mysqld.log', /(SLES|SLED)/ => '/var/log/mysqld.log', } $pidfile = $::operatingsystem ? { /OpenSuSE/ => '/var/run/mysql/mysqld.pid', /(SLES|SLED)/ => '/var/lib/mysql/mysqld.pid', } $root_group = 'root' $mysql_group = 'mysql' $server_service_name = 'mysql' if $::operatingsystem =~ /(SLES|SLED)/ { if versioncmp( $::operatingsystemmajrelease, '12' ) >= 0 { $socket = '/run/mysql/mysql.sock' } else { $socket = '/var/lib/mysql/mysql.sock' } } else { $socket = '/var/run/mysql/mysql.sock' } $ssl_ca = '/etc/mysql/cacert.pem' $ssl_cert = '/etc/mysql/server-cert.pem' $ssl_key = '/etc/mysql/server-key.pem' $tmpdir = '/tmp' # mysql::bindings $java_package_name = 'mysql-connector-java' $perl_package_name = 'perl-DBD-mysql' $php_package_name = 'apache2-mod_php53' $python_package_name = 'python-mysql' $ruby_package_name = $::operatingsystem ? { /OpenSuSE/ => 'rubygem-mysql', /(SLES|SLED)/ => 'ruby-mysql', } $client_dev_package_name = 'libmysqlclient-devel' $daemon_dev_package_name = 'mysql-devel' } 'Debian': { $client_package_name = 'mysql-client' $server_package_name = 'mysql-server' $basedir = '/usr' $config_file = '/etc/mysql/my.cnf' $includedir = '/etc/mysql/conf.d' $datadir = '/var/lib/mysql' $log_error = '/var/log/mysql/error.log' $pidfile = '/var/run/mysqld/mysqld.pid' $root_group = 'root' $mysql_group = 'adm' $server_service_name = 'mysql' $socket = '/var/run/mysqld/mysqld.sock' $ssl_ca = '/etc/mysql/cacert.pem' $ssl_cert = '/etc/mysql/server-cert.pem' $ssl_key = '/etc/mysql/server-key.pem' $tmpdir = '/tmp' # mysql::bindings $java_package_name = 'libmysql-java' $perl_package_name = 'libdbd-mysql-perl' $php_package_name = $::lsbdistcodename ? { 'xenial' => 'php-mysql', default => 'php5-mysql', } $python_package_name = 'python-mysqldb' $ruby_package_name = $::lsbdistcodename ? { 'trusty' => 'ruby-mysql', 'jessie' => 'ruby-mysql', 'xenial' => 'ruby-mysql', default => 'libmysql-ruby', } $client_dev_package_name = 'libmysqlclient-dev' $daemon_dev_package_name = 'libmysqld-dev' } 'Archlinux': { $client_package_name = 'mariadb-clients' $server_package_name = 'mariadb' $basedir = '/usr' $config_file = '/etc/mysql/my.cnf' $datadir = '/var/lib/mysql' $log_error = '/var/log/mysqld.log' $pidfile = '/var/run/mysqld/mysqld.pid' $root_group = 'root' $mysql_group = 'mysql' $server_service_name = 'mysqld' $socket = '/var/lib/mysql/mysql.sock' $ssl_ca = '/etc/mysql/cacert.pem' $ssl_cert = '/etc/mysql/server-cert.pem' $ssl_key = '/etc/mysql/server-key.pem' $tmpdir = '/tmp' # mysql::bindings $java_package_name = 'mysql-connector-java' $perl_package_name = 'perl-dbd-mysql' $php_package_name = undef $python_package_name = 'mysql-python' $ruby_package_name = 'mysql-ruby' } 'Gentoo': { $client_package_name = 'virtual/mysql' $server_package_name = 'virtual/mysql' $basedir = '/usr' $config_file = '/etc/mysql/my.cnf' $datadir = '/var/lib/mysql' $log_error = '/var/log/mysql/mysqld.err' $pidfile = '/run/mysqld/mysqld.pid' $root_group = 'root' $mysql_group = 'mysql' $server_service_name = 'mysql' $socket = '/run/mysqld/mysqld.sock' $ssl_ca = '/etc/mysql/cacert.pem' $ssl_cert = '/etc/mysql/server-cert.pem' $ssl_key = '/etc/mysql/server-key.pem' $tmpdir = '/tmp' # mysql::bindings $java_package_name = 'dev-java/jdbc-mysql' $perl_package_name = 'dev-perl/DBD-mysql' $php_package_name = undef $python_package_name = 'dev-python/mysql-python' $ruby_package_name = 'dev-ruby/mysql-ruby' } 'FreeBSD': { $client_package_name = 'databases/mysql56-client' $server_package_name = 'databases/mysql56-server' $basedir = '/usr/local' $config_file = '/usr/local/etc/my.cnf' $includedir = '/usr/local/etc/my.cnf.d' $datadir = '/var/db/mysql' $log_error = '/var/log/mysqld.log' $pidfile = '/var/run/mysql.pid' $root_group = 'wheel' $mysql_group = 'mysql' $server_service_name = 'mysql-server' $socket = '/var/db/mysql/mysql.sock' $ssl_ca = undef $ssl_cert = undef $ssl_key = undef $tmpdir = '/tmp' # mysql::bindings $java_package_name = 'databases/mysql-connector-java' $perl_package_name = 'p5-DBD-mysql' $php_package_name = 'php5-mysql' $python_package_name = 'databases/py-MySQLdb' $ruby_package_name = 'databases/ruby-mysql' # The libraries installed by these packages are included in client and server packages, no installation required. $client_dev_package_name = undef $daemon_dev_package_name = undef } 'OpenBSD': { $client_package_name = 'mariadb-client' $server_package_name = 'mariadb-server' $basedir = '/usr/local' $config_file = '/etc/my.cnf' $includedir = undef $datadir = '/var/mysql' $log_error = "/var/mysql/${::hostname}.err" $pidfile = '/var/mysql/mysql.pid' $root_group = 'wheel' $mysql_group = '_mysql' $server_service_name = 'mysqld' $socket = '/var/run/mysql/mysql.sock' $ssl_ca = undef $ssl_cert = undef $ssl_key = undef $tmpdir = '/tmp' # mysql::bindings $java_package_name = undef $perl_package_name = 'p5-DBD-mysql' $php_package_name = 'php-mysql' $python_package_name = 'py-mysql' $ruby_package_name = 'ruby-mysql' # The libraries installed by these packages are included in client and server packages, no installation required. $client_dev_package_name = undef $daemon_dev_package_name = undef } 'Solaris': { $client_package_name = 'database/mysql-55/client' $server_package_name = 'database/mysql-55' $basedir = undef $config_file = '/etc/mysql/5.5/my.cnf' $datadir = '/var/mysql/5.5/data' $log_error = "/var/mysql/5.5/data/${::hostname}.err" $pidfile = "/var/mysql/5.5/data/${::hostname}.pid" $root_group = 'bin' $server_service_name = 'application/database/mysql:version_55' $socket = '/tmp/mysql.sock' $ssl_ca = undef $ssl_cert = undef $ssl_key = undef $tmpdir = '/tmp' # mysql::bindings $java_package_name = undef $perl_package_name = undef $php_package_name = 'web/php-53/extension/php-mysql' $python_package_name = 'library/python/python-mysql' $ruby_package_name = undef # The libraries installed by these packages are included in client and server packages, no installation required. $client_dev_package_name = undef $daemon_dev_package_name = undef } default: { case $::operatingsystem { 'Amazon': { $client_package_name = 'mysql' $server_package_name = 'mysql-server' $basedir = '/usr' $config_file = '/etc/my.cnf' $includedir = '/etc/my.cnf.d' $datadir = '/var/lib/mysql' $log_error = '/var/log/mysqld.log' $pidfile = '/var/run/mysqld/mysqld.pid' $root_group = 'root' $mysql_group = 'mysql' $server_service_name = 'mysqld' $socket = '/var/lib/mysql/mysql.sock' $ssl_ca = '/etc/mysql/cacert.pem' $ssl_cert = '/etc/mysql/server-cert.pem' $ssl_key = '/etc/mysql/server-key.pem' $tmpdir = '/tmp' # mysql::bindings $java_package_name = 'mysql-connector-java' $perl_package_name = 'perl-DBD-MySQL' $php_package_name = 'php-mysql' $python_package_name = 'MySQL-python' $ruby_package_name = 'ruby-mysql' # The libraries installed by these packages are included in client and server packages, no installation required. $client_dev_package_name = undef $daemon_dev_package_name = undef } default: { fail("Unsupported platform: puppetlabs-${module_name} currently doesn't support ${::osfamily} or ${::operatingsystem}") } } } } case $::operatingsystem { 'Ubuntu': { if versioncmp($::operatingsystemmajrelease, '14.10') > 0 { $server_service_provider = 'systemd' } else { $server_service_provider = 'upstart' } } default: { $server_service_provider = undef } } $default_options = { 'client' => { 'port' => '3306', 'socket' => $mysql::params::socket, }, 'mysqld_safe' => { 'nice' => '0', 'log-error' => $mysql::params::log_error, 'socket' => $mysql::params::socket, }, 'mysqld-5.0' => { 'myisam-recover' => 'BACKUP', }, 'mysqld-5.1' => { 'myisam-recover' => 'BACKUP', }, 'mysqld-5.5' => { 'myisam-recover' => 'BACKUP', }, 'mysqld-5.6' => { 'myisam-recover-options' => 'BACKUP', }, 'mysqld-5.7' => { 'myisam-recover-options' => 'BACKUP', }, 'mysqld' => { 'basedir' => $mysql::params::basedir, 'bind-address' => '127.0.0.1', 'datadir' => $mysql::params::datadir, 'expire_logs_days' => '10', 'key_buffer_size' => '16M', 'log-error' => $mysql::params::log_error, 'max_allowed_packet' => '16M', 'max_binlog_size' => '100M', 'max_connections' => '151', 'pid-file' => $mysql::params::pidfile, 'port' => '3306', 'query_cache_limit' => '1M', 'query_cache_size' => '16M', 'skip-external-locking' => true, 'socket' => $mysql::params::socket, 'ssl' => false, 'ssl-ca' => $mysql::params::ssl_ca, 'ssl-cert' => $mysql::params::ssl_cert, 'ssl-key' => $mysql::params::ssl_key, 'ssl-disable' => false, 'thread_cache_size' => '8', 'thread_stack' => '256K', 'tmpdir' => $mysql::params::tmpdir, 'user' => 'mysql', }, 'mysqldump' => { 'max_allowed_packet' => '16M', 'quick' => true, 'quote-names' => true, }, 'isamchk' => { 'key_buffer_size' => '16M', }, } ## Additional graceful failures if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '4' and $::operatingsystem != 'Amazon' { fail("Unsupported platform: puppetlabs-${module_name} only supports RedHat 5.0 and beyond") } } puppetlabs-mysql-3.10.0/manifests/server.pp0000644005276200011600000000624512763636535020674 0ustar jenkinsjenkins# Class: mysql::server: See README.md for documentation. class mysql::server ( $config_file = $mysql::params::config_file, $includedir = $mysql::params::includedir, $install_options = undef, $install_secret_file = $mysql::params::install_secret_file, $manage_config_file = $mysql::params::manage_config_file, $override_options = {}, $package_ensure = $mysql::params::server_package_ensure, $package_manage = $mysql::params::server_package_manage, $package_name = $mysql::params::server_package_name, $purge_conf_dir = $mysql::params::purge_conf_dir, $remove_default_accounts = false, $restart = $mysql::params::restart, $root_group = $mysql::params::root_group, $mysql_group = $mysql::params::mysql_group, $root_password = $mysql::params::root_password, $service_enabled = $mysql::params::server_service_enabled, $service_manage = $mysql::params::server_service_manage, $service_name = $mysql::params::server_service_name, $service_provider = $mysql::params::server_service_provider, $create_root_user = $mysql::params::create_root_user, $create_root_my_cnf = $mysql::params::create_root_my_cnf, $users = {}, $grants = {}, $databases = {}, # Deprecated parameters $enabled = undef, $manage_service = undef, $old_root_password = undef ) inherits mysql::params { # Deprecated parameters. if $enabled { crit('This parameter has been renamed to service_enabled.') $real_service_enabled = $enabled } else { $real_service_enabled = $service_enabled } if $manage_service { crit('This parameter has been renamed to service_manage.') $real_service_manage = $manage_service } else { $real_service_manage = $service_manage } if $old_root_password { warning('old_root_password is no longer used and will be removed in a future release') } # Create a merged together set of options. Rightmost hashes win over left. $options = mysql_deepmerge($mysql::params::default_options, $override_options) Class['mysql::server::root_password'] -> Mysql::Db <| |> include '::mysql::server::config' include '::mysql::server::install' include '::mysql::server::binarylog' include '::mysql::server::installdb' include '::mysql::server::service' include '::mysql::server::root_password' include '::mysql::server::providers' if $remove_default_accounts { class { '::mysql::server::account_security': require => Anchor['mysql::server::end'], } } anchor { 'mysql::server::start': } anchor { 'mysql::server::end': } if $restart { Class['mysql::server::config'] ~> Class['mysql::server::service'] } Anchor['mysql::server::start'] -> Class['mysql::server::config'] -> Class['mysql::server::install'] -> Class['mysql::server::binarylog'] -> Class['mysql::server::installdb'] -> Class['mysql::server::service'] -> Class['mysql::server::root_password'] -> Class['mysql::server::providers'] -> Anchor['mysql::server::end'] } puppetlabs-mysql-3.10.0/manifests/client.pp0000644005276200011600000000143312746170223020622 0ustar jenkinsjenkins# class mysql::client ( $bindings_enable = $mysql::params::bindings_enable, $install_options = undef, $package_ensure = $mysql::params::client_package_ensure, $package_manage = $mysql::params::client_package_manage, $package_name = $mysql::params::client_package_name, ) inherits mysql::params { include '::mysql::client::install' if $bindings_enable { class { 'mysql::bindings': java_enable => true, perl_enable => true, php_enable => true, python_enable => true, ruby_enable => true, } } # Anchor pattern workaround to avoid resources of mysql::client::install to # "float off" outside mysql::client anchor { 'mysql::client::start': } -> Class['mysql::client::install'] -> anchor { 'mysql::client::end': } } puppetlabs-mysql-3.10.0/manifests/backup/0000755005276200011600000000000013010160602020230 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/manifests/backup/mysqlbackup.pp0000644005276200011600000000615012763636535023161 0ustar jenkinsjenkins# See README.me for usage. class mysql::backup::mysqlbackup ( $backupuser = '', $backuppassword = '', $maxallowedpacket = '1M', $backupdir = '', $backupdirmode = '0700', $backupdirowner = 'root', $backupdirgroup = $mysql::params::root_group, $backupcompress = true, $backuprotate = 30, $ignore_events = true, $delete_before_dump = false, $backupdatabases = [], $file_per_database = false, $include_triggers = true, $include_routines = false, $ensure = 'present', $time = ['23', '5'], $prescript = false, $postscript = false, $execpath = '/usr/bin:/usr/sbin:/bin:/sbin', ) inherits mysql::params { mysql_user { "${backupuser}@localhost": ensure => $ensure, password_hash => mysql_password($backuppassword), require => Class['mysql::server::root_password'], } package { 'meb': ensure => $ensure, } # http://dev.mysql.com/doc/mysql-enterprise-backup/3.11/en/mysqlbackup.privileges.html mysql_grant { "${backupuser}@localhost/*.*": ensure => $ensure, user => "${backupuser}@localhost", table => '*.*', privileges => [ 'RELOAD', 'SUPER', 'REPLICATION CLIENT' ], require => Mysql_user["${backupuser}@localhost"], } mysql_grant { "${backupuser}@localhost/mysql.backup_progress": ensure => $ensure, user => "${backupuser}@localhost", table => 'mysql.backup_progress', privileges => [ 'CREATE', 'INSERT', 'DROP', 'UPDATE' ], require => Mysql_user["${backupuser}@localhost"], } mysql_grant { "${backupuser}@localhost/mysql.backup_history": ensure => $ensure, user => "${backupuser}@localhost", table => 'mysql.backup_history', privileges => [ 'CREATE', 'INSERT', 'SELECT', 'DROP', 'UPDATE' ], require => Mysql_user["${backupuser}@localhost"], } cron { 'mysqlbackup-weekly': ensure => $ensure, command => 'mysqlbackup backup', user => 'root', hour => $time[0], minute => $time[1], weekday => '0', require => Package['meb'], } cron { 'mysqlbackup-daily': ensure => $ensure, command => 'mysqlbackup --incremental backup', user => 'root', hour => $time[0], minute => $time[1], weekday => '1-6', require => Package['meb'], } $default_options = { 'mysqlbackup' => { 'backup-dir' => $backupdir, 'with-timestamp' => true, 'incremental_base' => 'history:last_backup', 'incremental_backup_dir' => $backupdir, 'user' => $backupuser, 'password' => $backuppassword, } } $options = mysql_deepmerge($default_options, $mysql::server::override_options) file { 'mysqlbackup-config-file': path => '/etc/mysql/conf.d/meb.cnf', content => template('mysql/meb.cnf.erb'), mode => '0600', } file { 'mysqlbackupdir': ensure => 'directory', path => $backupdir, mode => $backupdirmode, owner => $backupdirowner, group => $backupdirgroup, } } puppetlabs-mysql-3.10.0/manifests/backup/mysqldump.pp0000644005276200011600000000402212763636535022655 0ustar jenkinsjenkins# See README.me for usage. class mysql::backup::mysqldump ( $backupuser = '', $backuppassword = '', $backupdir = '', $maxallowedpacket = '1M', $backupdirmode = '0700', $backupdirowner = 'root', $backupdirgroup = $mysql::params::root_group, $backupcompress = true, $backuprotate = 30, $ignore_events = true, $delete_before_dump = false, $backupdatabases = [], $file_per_database = false, $include_triggers = false, $include_routines = false, $ensure = 'present', $time = ['23', '5'], $prescript = false, $postscript = false, $execpath = '/usr/bin:/usr/sbin:/bin:/sbin', ) inherits mysql::params { ensure_packages(['bzip2']) mysql_user { "${backupuser}@localhost": ensure => $ensure, password_hash => mysql_password($backuppassword), require => Class['mysql::server::root_password'], } if $include_triggers { $privs = [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS', 'TRIGGER' ] } else { $privs = [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS' ] } mysql_grant { "${backupuser}@localhost/*.*": ensure => $ensure, user => "${backupuser}@localhost", table => '*.*', privileges => $privs, require => Mysql_user["${backupuser}@localhost"], } cron { 'mysql-backup': ensure => $ensure, command => '/usr/local/sbin/mysqlbackup.sh', user => 'root', hour => $time[0], minute => $time[1], require => [File['mysqlbackup.sh'], Package['bzip2']], } file { 'mysqlbackup.sh': ensure => $ensure, path => '/usr/local/sbin/mysqlbackup.sh', mode => '0700', owner => 'root', group => $mysql::params::root_group, content => template('mysql/mysqlbackup.sh.erb'), } file { 'mysqlbackupdir': ensure => 'directory', path => $backupdir, mode => $backupdirmode, owner => $backupdirowner, group => $backupdirgroup, } } puppetlabs-mysql-3.10.0/manifests/backup/xtrabackup.pp0000644005276200011600000000370612763636535022776 0ustar jenkinsjenkins# See README.me for usage. class mysql::backup::xtrabackup ( $xtrabackup_package_name = $mysql::params::xtrabackup_package_name, $backupuser = '', $backuppassword = '', $backupdir = '', $maxallowedpacket = '1M', $backupmethod = 'mysqldump', $backupdirmode = '0700', $backupdirowner = 'root', $backupdirgroup = $mysql::params::root_group, $backupcompress = true, $backuprotate = 30, $ignore_events = true, $delete_before_dump = false, $backupdatabases = [], $file_per_database = false, $include_triggers = true, $include_routines = false, $ensure = 'present', $time = ['23', '5'], $prescript = false, $postscript = false, $execpath = '/usr/bin:/usr/sbin:/bin:/sbin', ) inherits mysql::params { package{ $xtrabackup_package_name: ensure => $ensure, } cron { 'xtrabackup-weekly': ensure => $ensure, command => "/usr/local/sbin/xtrabackup.sh ${backupdir}", user => 'root', hour => $time[0], minute => $time[1], weekday => '0', require => Package[$xtrabackup_package_name], } cron { 'xtrabackup-daily': ensure => $ensure, command => "/usr/local/sbin/xtrabackup.sh --incremental ${backupdir}", user => 'root', hour => $time[0], minute => $time[1], weekday => '1-6', require => Package[$xtrabackup_package_name], } file { 'mysqlbackupdir': ensure => 'directory', path => $backupdir, mode => $backupdirmode, owner => $backupdirowner, group => $backupdirgroup, } file { 'xtrabackup.sh': ensure => $ensure, path => '/usr/local/sbin/xtrabackup.sh', mode => '0700', owner => 'root', group => $mysql::params::root_group, content => template('mysql/xtrabackup.sh.erb'), } } puppetlabs-mysql-3.10.0/manifests/server/0000755005276200011600000000000013010160602020271 5ustar jenkinsjenkinspuppetlabs-mysql-3.10.0/manifests/server/service.pp0000644005276200011600000000342512746170223022315 0ustar jenkinsjenkins# class mysql::server::service { $options = $mysql::server::options if $mysql::server::real_service_manage { if $mysql::server::real_service_enabled { $service_ensure = 'running' } else { $service_ensure = 'stopped' } } else { $service_ensure = undef } if $mysql::server::override_options and $mysql::server::override_options['mysqld'] and $mysql::server::override_options['mysqld']['user'] { $mysqluser = $mysql::server::override_options['mysqld']['user'] } else { $mysqluser = $options['mysqld']['user'] } if $mysql::server::real_service_manage { service { 'mysqld': ensure => $service_ensure, name => $mysql::server::service_name, enable => $mysql::server::real_service_enabled, provider => $mysql::server::service_provider, } # only establish ordering between service and package if # we're managing the package. if $mysql::server::package_manage { Service['mysqld'] { require => Package['mysql-server'], } } # only establish ordering between config file and service if # we're managing the config file. if $mysql::server::manage_config_file { File['mysql-config-file'] -> Service['mysqld'] } if $mysql::server::override_options and $mysql::server::override_options['mysqld'] and $mysql::server::override_options['mysqld']['socket'] { $mysqlsocket = $mysql::server::override_options['mysqld']['socket'] } else { $mysqlsocket = $options['mysqld']['socket'] } exec { 'wait_for_mysql_socket_to_open': command => "test -S ${mysqlsocket}", unless => "test -S ${mysqlsocket}", tries => '3', try_sleep => '10', require => Service['mysqld'], path => '/bin:/usr/bin', } } } puppetlabs-mysql-3.10.0/manifests/server/mysqltuner.pp0000644005276200011600000000264712746170223023105 0ustar jenkinsjenkins# class mysql::server::mysqltuner( $ensure = 'present', $version = 'v1.3.0', $source = undef, ) { if $source { $_version = $source $_source = $source } else { $_version = $version $_source = "https://github.com/major/MySQLTuner-perl/raw/${version}/mysqltuner.pl" } if $ensure == 'present' { # $::puppetversion doesn't exist in puppet 4.x so would break strict # variables if ! $::settings::strict_variables { $_puppetversion = $::puppetversion } else { # defined only works with puppet >= 3.5.0, so don't use it unless we're # actually using strict variables $_puppetversion = defined('$puppetversion') ? { true => $::puppetversion, default => undef, } } # see https://tickets.puppetlabs.com/browse/ENTERPRISE-258 if $_puppetversion and $_puppetversion =~ /Puppet Enterprise/ and versioncmp($_puppetversion, '3.8.0') < 0 { class { '::staging': path => '/opt/mysql_staging', } } else { class { '::staging': } } staging::file { "mysqltuner-${_version}": source => $_source, } file { '/usr/local/bin/mysqltuner': ensure => $ensure, mode => '0550', source => "${::staging::path}/mysql/mysqltuner-${_version}", require => Staging::File["mysqltuner-${_version}"], } } else { file { '/usr/local/bin/mysqltuner': ensure => $ensure, } } } puppetlabs-mysql-3.10.0/manifests/server/install.pp0000644005276200011600000000043612746170223022322 0ustar jenkinsjenkins# class mysql::server::install { if $mysql::server::package_manage { package { 'mysql-server': ensure => $mysql::server::package_ensure, install_options => $mysql::server::install_options, name => $mysql::server::package_name, } } } puppetlabs-mysql-3.10.0/manifests/server/config.pp0000644005276200011600000000354312763636535022137 0ustar jenkinsjenkins# See README.me for options. class mysql::server::config { $options = $mysql::server::options $includedir = $mysql::server::includedir File { owner => 'root', group => $mysql::server::root_group, mode => '0400', } if $includedir and $includedir != '' { file { $includedir: ensure => directory, mode => '0755', recurse => $mysql::server::purge_conf_dir, purge => $mysql::server::purge_conf_dir, } # on some systems this is /etc/my.cnf.d, while Debian has /etc/mysql/conf.d and FreeBSD something in /usr/local. For the latter systems, # managing this basedir is also required, to have it available before the package is installed. $includeparentdir = mysql_dirname($includedir) if $includeparentdir != '/' and $includeparentdir != '/etc' { file { $includeparentdir: ensure => directory, mode => '0755', } } } if $mysql::server::manage_config_file { file { 'mysql-config-file': path => $mysql::server::config_file, content => template('mysql/my.cnf.erb'), mode => '0644', selinux_ignore_defaults => true, } # on mariadb systems, $includedir is not defined, but /etc/my.cnf.d has # to be managed to place the server.cnf there $configparentdir = mysql_dirname($mysql::server::config_file) if $configparentdir != '/' and $configparentdir != '/etc' and $configparentdir != $includedir and $configparentdir != mysql_dirname($includedir) { file { $configparentdir: ensure => directory, mode => '0755', } } } if $options['mysqld']['ssl-disable'] { notify {'ssl-disable': message =>'Disabling SSL is evil! You should never ever do this except if you are forced to use a mysql version compiled without SSL support' } } } puppetlabs-mysql-3.10.0/manifests/server/monitor.pp0000644005276200011600000000146212746170223022343 0ustar jenkinsjenkins#This is a helper class to add a monitoring user to the database class mysql::server::monitor ( $mysql_monitor_username = '', $mysql_monitor_password = '', $mysql_monitor_hostname = '' ) { Anchor['mysql::server::end'] -> Class['mysql::server::monitor'] mysql_user { "${mysql_monitor_username}@${mysql_monitor_hostname}": ensure => present, password_hash => mysql_password($mysql_monitor_password), require => Class['mysql::server::service'], } mysql_grant { "${mysql_monitor_username}@${mysql_monitor_hostname}/*.*": ensure => present, user => "${mysql_monitor_username}@${mysql_monitor_hostname}", table => '*.*', privileges => [ 'PROCESS', 'SUPER' ], require => Mysql_user["${mysql_monitor_username}@${mysql_monitor_hostname}"], } } puppetlabs-mysql-3.10.0/manifests/server/binarylog.pp0000644005276200011600000000122712763636535022655 0ustar jenkinsjenkins# Binary log configuration requires the mysql user to be present. This must be done after package install class mysql::server::binarylog { $options = $mysql::server::options $includedir = $mysql::server::includedir $logbin = pick($options['mysqld']['log-bin'], $options['mysqld']['log_bin'], false) if $logbin { $logbindir = mysql_dirname($logbin) #Stop puppet from managing directory if just a filename/prefix is specified if $logbindir != '.' { file { $logbindir: ensure => directory, mode => '0755', owner => $options['mysqld']['user'], group => $options['mysqld']['user'], } } } } puppetlabs-mysql-3.10.0/manifests/server/providers.pp0000644005276200011600000000054512746170216022674 0ustar jenkinsjenkins# Convenience class to call each of the three providers with the corresponding # hashes provided in mysql::server. # See README.md for details. class mysql::server::providers { create_resources('mysql_user', $mysql::server::users) create_resources('mysql_grant', $mysql::server::grants) create_resources('mysql_database', $mysql::server::databases) } puppetlabs-mysql-3.10.0/manifests/server/backup.pp0000644005276200011600000000356512763636535022143 0ustar jenkinsjenkins# See README.me for usage. class mysql::server::backup ( $backupuser = undef, $backuppassword = undef, $backupdir = undef, $backupdirmode = '0700', $backupdirowner = 'root', $backupdirgroup = 'root', $backupcompress = true, $backuprotate = 30, $ignore_events = true, $delete_before_dump = false, $backupdatabases = [], $file_per_database = false, $include_routines = false, $include_triggers = false, $ensure = 'present', $time = ['23', '5'], $prescript = false, $postscript = false, $execpath = '/usr/bin:/usr/sbin:/bin:/sbin', $provider = 'mysqldump', $maxallowedpacket = '1M', ) { if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ { warning("The \$prescript option is not currently implemented for the ${provider} backup provider.") } create_resources('class', { "mysql::backup::${provider}" => { 'backupuser' => $backupuser, 'backuppassword' => $backuppassword, 'backupdir' => $backupdir, 'backupdirmode' => $backupdirmode, 'backupdirowner' => $backupdirowner, 'backupdirgroup' => $backupdirgroup, 'backupcompress' => $backupcompress, 'backuprotate' => $backuprotate, 'ignore_events' => $ignore_events, 'delete_before_dump' => $delete_before_dump, 'backupdatabases' => $backupdatabases, 'file_per_database' => $file_per_database, 'include_routines' => $include_routines, 'include_triggers' => $include_triggers, 'ensure' => $ensure, 'time' => $time, 'prescript' => $prescript, 'postscript' => $postscript, 'execpath' => $execpath, 'maxallowedpacket' => $maxallowedpacket, } }) } puppetlabs-mysql-3.10.0/manifests/server/account_security.pp0000644005276200011600000000170312763636535024251 0ustar jenkinsjenkins# See README.md. class mysql::server::account_security { mysql_user { [ 'root@127.0.0.1', 'root@::1', '@localhost', '@%']: ensure => 'absent', require => Anchor['mysql::server::end'], } if ($::fqdn != 'localhost.localdomain') { mysql_user { [ 'root@localhost.localdomain', '@localhost.localdomain']: ensure => 'absent', require => Anchor['mysql::server::end'], } } if ($::fqdn and $::fqdn != 'localhost') { mysql_user { [ "root@${::fqdn}", "@${::fqdn}"]: ensure => 'absent', require => Anchor['mysql::server::end'], } } if ($::fqdn != $::hostname) { if ($::hostname != 'localhost') { mysql_user { ["root@${::hostname}", "@${::hostname}"]: ensure => 'absent', require => Anchor['mysql::server::end'], } } } mysql_database { 'test': ensure => 'absent', require => Anchor['mysql::server::end'], } } puppetlabs-mysql-3.10.0/manifests/server/root_password.pp0000644005276200011600000000317412746170223023563 0ustar jenkinsjenkins# class mysql::server::root_password { $options = $mysql::server::options $secret_file = $mysql::server::install_secret_file # New installations of MySQL will configure a default random password for the root user # with an expiration. No actions can be performed until this password is changed. The # below exec will remove this default password. If the user has supplied a root # password it will be set further down with the mysql_user resource. $rm_pass_cmd = join([ "mysqladmin -u root --password=\$(grep -o '[^ ]\\+\$' ${secret_file}) password ''", "rm -f ${secret_file}" ], ' && ') exec { 'remove install pass': command => $rm_pass_cmd, onlyif => "test -f ${secret_file}", path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin' } # manage root password if it is set if $mysql::server::create_root_user == true and $mysql::server::root_password != 'UNSET' { mysql_user { 'root@localhost': ensure => present, password_hash => mysql_password($mysql::server::root_password), require => Exec['remove install pass'] } } if $mysql::server::create_root_my_cnf == true and $mysql::server::root_password != 'UNSET' { file { "${::root_home}/.my.cnf": content => template('mysql/my.cnf.pass.erb'), owner => 'root', mode => '0600', } # show_diff was added with puppet 3.0 if versioncmp($::puppetversion, '3.0') >= 0 { File["${::root_home}/.my.cnf"] { show_diff => false } } if $mysql::server::create_root_user == true { Mysql_user['root@localhost'] -> File["${::root_home}/.my.cnf"] } } } puppetlabs-mysql-3.10.0/manifests/server/installdb.pp0000644005276200011600000000241012763636535022636 0ustar jenkinsjenkins# class mysql::server::installdb { $options = $mysql::server::options if $mysql::server::package_manage { # Build the initial databases. $mysqluser = $mysql::server::options['mysqld']['user'] $datadir = $mysql::server::options['mysqld']['datadir'] $basedir = $mysql::server::options['mysqld']['basedir'] $config_file = $mysql::server::config_file $log_error = $mysql::server::options['mysqld']['log-error'] if $mysql::server::manage_config_file and $config_file != $mysql::params::config_file { $_config_file=$config_file } else { $_config_file=undef } if $options['mysqld']['log-error'] { file { $options['mysqld']['log-error']: ensure => present, owner => $mysqluser, group => $::mysql::server::mysql_group, mode => 'u+rw', before => Mysql_datadir[ $datadir ], } } mysql_datadir { $datadir: ensure => 'present', datadir => $datadir, basedir => $basedir, user => $mysqluser, log_error => $log_error, defaults_extra_file => $_config_file, } if $mysql::server::restart { Mysql_datadir[$datadir] { notify => Class['mysql::server::service'], } } } } puppetlabs-mysql-3.10.0/manifests/db.pp0000644005276200011600000000364013010160217017716 0ustar jenkinsjenkins# See README.md for details. define mysql::db ( $user, $password, $dbname = $name, $charset = 'utf8', $collate = 'utf8_general_ci', $host = 'localhost', $grant = 'ALL', $sql = undef, $enforce_sql = false, $ensure = 'present', $import_timeout = 300, $import_cat_cmd = 'cat', ) { #input validation validate_re($ensure, '^(present|absent)$', "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.") $table = "${dbname}.*" if !(is_array($sql) or is_string($sql)) { fail('$sql must be either a string or an array.') } $sql_inputs = join([$sql], ' ') include '::mysql::client' $db_resource = { ensure => $ensure, charset => $charset, collate => $collate, provider => 'mysql', require => [ Class['mysql::client'] ], } ensure_resource('mysql_database', $dbname, $db_resource) $user_resource = { ensure => $ensure, password_hash => mysql_password($password), provider => 'mysql', } ensure_resource('mysql_user', "${user}@${host}", $user_resource) if $ensure == 'present' { mysql_grant { "${user}@${host}/${table}": privileges => $grant, provider => 'mysql', user => "${user}@${host}", table => $table, require => [ Mysql_database[$dbname], Mysql_user["${user}@${host}"], ], } $refresh = ! $enforce_sql if $sql { exec{ "${dbname}-import": command => "${import_cat_cmd} ${sql_inputs} | mysql ${dbname}", logoutput => true, environment => "HOME=${::root_home}", refreshonly => $refresh, path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin', require => Mysql_grant["${user}@${host}/${table}"], subscribe => Mysql_database[$dbname], timeout => $import_timeout, } } } }