Skip to content

Commit

Permalink
Simplifiy integer calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
theseal committed Oct 7, 2024
1 parent 19b4fde commit 13bde2c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/puppet/functions/ipv4_to_int.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true


# Convert a single IPv4 address to an int

require 'ipaddr'

Puppet::Functions.create_function(:ipv4_to_int) do
def ipv4_to_int(*arguments)
IPAddr.new(arguments[0]).to_i
end
end
2 changes: 2 additions & 0 deletions manifests/mariadb.pp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
content => template('sunet/mariadb/credentials.cnf.erb'),
mode => '0744',
}

$server_id = ipv4_to_int($facts['networking']['ip'])
file { "${mariadb_dir}/conf/my.cnf":
ensure => present,
content => template('sunet/mariadb/my.cnf.erb'),
Expand Down
3 changes: 1 addition & 2 deletions templates/mariadb/my.cnf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ gtid_ignore_duplicates = ON
gtid_strict_mode = ON
log_bin = binlog
log_slave_updates = ON
# Use IP adress as decimal in order to create an unique server id
server_id = <%= @facts['networking']['ip'].split(".").map(&:to_i).pack('CCCC').unpack('N')[0] %>
server_id = <%= @server_id %>
# Default hostname base relay_log is no good in containers
relay_log = 'relay-log'

Expand Down

0 comments on commit 13bde2c

Please sign in to comment.