diff options
author | Bryan McLellan <btm@loftninjas.org> | 2019-04-15 17:30:01 -0400 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2019-04-15 20:58:55 -0400 |
commit | 7f62eff6d676365c9e1a984728e9b02bbd74d3ae (patch) | |
tree | 7fe4975031717ea3dfac77f0789b1d57812d02c7 /lib/chef/resource/locale.rb | |
parent | 2fe2f5029df438ff92274b3240df5f5bee10c067 (diff) | |
download | chef-7f62eff6d676365c9e1a984728e9b02bbd74d3ae.tar.gz |
Limit locale resource to Linux
Platforms that don't use /etc/locale.conf aren't supported
Signed-off-by: Bryan McLellan <btm@loftninjas.org>
Diffstat (limited to 'lib/chef/resource/locale.rb')
-rw-r--r-- | lib/chef/resource/locale.rb | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/chef/resource/locale.rb b/lib/chef/resource/locale.rb index b16cfe7e3c..52170e8765 100644 --- a/lib/chef/resource/locale.rb +++ b/lib/chef/resource/locale.rb @@ -28,6 +28,7 @@ class Chef LC_VARIABLES = %w{LC_ADDRESS LC_COLLATE LC_CTYPE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME}.freeze LOCALE_CONF = "/etc/locale.conf".freeze LOCALE_REGEX = /\A\S+/.freeze + LOCALE_PLATFORM_FAMILIES = %w{debian}.freeze property :lang, String, description: "Sets the default system language.", @@ -71,28 +72,31 @@ class Chef update_locale end end - rescue - # It might affect debugging - raise "#{node['platform']} platform is not supported by the chef locale resource. " + - "If you believe this is in error please file an issue at https://github.com/chef/chef/issues" end end action_class do + # Avoid running this resource on platforms that don't use /etc/locale.conf + # + def define_resource_requirements + requirements.assert(:all_actions) do |a| + a.assertion { LOCALE_PLATFORM_FAMILIES.include?(node[:platform_family]) } + a.failure_message(Chef::Exceptions::ProviderNotFound, "The locale resource is not supported on platform family: #{node[:platform_family]}") + end + + requirements.assert(:all_actions) do |a| + # RHEL/CentOS type platforms don't have locale-gen + a.assertion { shell_out("locale-gen") } + a.failure_message(Chef::Exceptions::ProviderNotFound, "The locale resource requires the locale-gen tool") + end + end # Generates the localisation files from templates using locale-gen. # @see http://manpages.ubuntu.com/manpages/cosmic/man8/locale-gen.8.html # @raise [Mixlib::ShellOut::ShellCommandFailed] not a supported language or locale # def generate_locales - bash "Generating locales: #{unavailable_locales.join(' ')}" do - code <<~CODE - if type locale-gen >/dev/null 2>&1 - then - locale-gen #{unavailable_locales.join(' ')} - fi - CODE - end + shell_out!("locale-gen #{unavailable_locales.join(' ')}") end # Updates system locale by appropriately writing them in /etc/locale.conf |