diff --git a/manifests/init.pp b/manifests/init.pp index a3fb9cf..c051718 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -179,8 +179,16 @@ $locale_template = 'locale.erb' } + case $ensure { + 'present': { + $default_file_ensure = 'file' + } + default: { + $default_file_ensure = 'absent' + } + } file { $default_file: - ensure => $ensure, + ensure => $default_file_ensure, owner => 'root', group => 0, mode => '0644', @@ -189,10 +197,17 @@ } $debian_legacy_location = '/etc/default/locale' - if $facts['os']['family'] == 'Debian' and $default_file != $debian_legacy_location { - file { $debian_legacy_location: - ensure => $ensure, - target => $default_file, + $debian_new_location = '/etc/locale.conf' + if $facts['os']['family'] == 'Debian' { + if $default_file == $debian_legacy_location { + file { $debian_new_location: + ensure => absent, + } + } else { + file { $debian_legacy_location: + ensure => $ensure, + target => '../locale.conf', + } } } diff --git a/manifests/params.pp b/manifests/params.pp index 8f076d5..b1e4376 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -37,7 +37,7 @@ $config_file = '/etc/locale.gen' } /(Debian|Raspbian|Kali|Parrot)/: { - if versioncmp($facts['os']['release']['major'], '12') >= 0 { + if versioncmp($facts['os']['release']['major'], '13') >= 0 { $default_file = '/etc/locale.conf' } else { $default_file = '/etc/default/locale' diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 0ee2de4..a1a28d9 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -18,18 +18,20 @@ case facts[:os]['family'].downcase when 'debian' + debian_legacy_location = '/etc/default/locale' + debian_new_location = '/etc/locale.conf' case facts[:os]['name'].downcase when 'debian' - default_file = if Gem::Version.new(facts[:os]['release']['major']) >= Gem::Version.new('12') - '/etc/locale.conf' + default_file = if Gem::Version.new(facts[:os]['release']['major']) > Gem::Version.new('12') + debian_new_location else - '/etc/default/locale' + debian_legacy_location end when 'ubuntu' default_file = if Gem::Version.new(facts[:os]['release']['full']) >= Gem::Version.new('24.04') - '/etc/locale.conf' + debian_new_location else - '/etc/default/locale' + debian_legacy_location end end when 'sles', 'suse' @@ -38,21 +40,29 @@ default_file = '/etc/locale.conf' end - if os =~ (%r{^(debian|ubuntu)}) && (default_file != '/etc/default/locale') - it do - is_expected.to contain_file('/etc/default/locale').with( - 'ensure' => 'present', - 'target' => '/etc/locale.conf' - ) - end - else - it do - is_expected.to contain_file(default_file).with( - 'ensure' => 'present', - 'owner' => 'root', - 'group' => 0, - 'mode' => '0644' - ) + it do + is_expected.to contain_file(default_file).with( + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 0, + 'mode' => '0644' + ) + end + + if os =~ (%r{^(debian|ubuntu)}) + if default_file == debian_legacy_location + it do + is_expected.to contain_file(debian_new_location).with( + 'ensure' => 'absent' + ) + end + else + it do + is_expected.to contain_file(debian_legacy_location).with( + 'ensure' => 'present', + 'target' => '../locale.conf' + ) + end end end end