puppet-prod/modules/facts/lib/facter/mariadb_datapath.rb
Ben Vincent 1f7b347ef4 refacter: tidy facts
- create a facts module, move all facts to this module
2024-02-17 22:57:36 +11:00

23 lines
539 B
Ruby

# frozen_string_literal: true
# check if the /etc/my.cnf.d/server.cnf file exists,
# open it and search for the 'datadir =' option
# store the datadir value as this fact
require 'facter'
Facter.add('mariadb_datapath') do
setcode do
if File.exist?('/etc/my.cnf.d/server.cnf')
datadir = nil
File.foreach('/etc/my.cnf.d/server.cnf') do |line|
match = line.match(/^\s*datadir\s*=\s*(.+)\s*$/)
if match
datadir = match[1].strip
break
end
end
datadir
end
end
end