Git Product home page Git Product logo

locale's Introduction

locale cookbook

Build Status Cookbook Version

Sets the default system locale for this system. You can see which locales are available by running locale -a.

On Debian based systems, this recipe sets the locale by running update-locale and on Fedora, it uses localectl.

On RHEL based systems, the recipe operates on the /etc/sysconfig/i18n file directly because there is no standard command line tool to change the system locale settings.

Deprecation

This locale resource is now shipped built-in with Chef 14.5 or later. This cookbook will continue to function with older chef-client releases, but all updates will now be performed directly in the chef-client codebase.

Requirements

Platforms

  • Debian / Ubuntu derivatives
  • openSUSE / SUSE Linux Enterprises
  • RHEL/CentOS/Scientific/Amazon/Oracle
  • Fedora

Chef

  • Chef 12.7+

Usage

  • Include the cookbook in your metadata.
locale 'set locale' do
  lang 'en_gb.utf-8'
  lc_all 'en_gb.utf-8'
end

Properties

name type default value
lang String en_US.utf8
lc_all String en_US.utf8

Maintainers

This cookbook is maintained by Chef's Community Cookbook Engineering team. Our goal is to improve cookbook quality and to aid the community in contributing to cookbooks. To learn more about our team, process, and design goals see our team documentation. To learn more about contributing to cookbooks like this see our contributing documentation, or if you have general questions about this cookbook come chat with us in #cookbok-engineering on the Chef Community Slack

License

Copyright: 2016-2018, Chef Software, Inc.

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.

locale's People

Contributors

agoddard avatar bluk avatar crawley avatar damacus avatar dje avatar dlutzy avatar f440 avatar lamont-granquist avatar luckymike avatar ponyfleisch avatar portertech avatar tas50 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

locale's Issues

update-locale failure for Raspbian Jessie (Debian)

Cookbook version

2.0.1

Chef-client version

chef-client --version
Chef: 13.2.20

Platform Details

cat /etc/*-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian

Scenario:

Running locale on newly formatted Raspberry Pi.
Command "update-locale LANG=#{lang} LC_ALL=#{lc_all}" fails with:
*** update-locale: Error: invalid locale settings: LC_ALL=en_US.UTF-8 LANG=en_GB.UTF-8

Steps to Reproduce:

You can easily reproduce this by running this command on a fresh Raspberry Pi running Raspbian Jessie:
update-locale LANG=en_US.utf8 LC_ALL=en_US.utf8

Expected Result:

I expect locale -a to return this after execution:
LANG=en_US.utf8
LANGUAGE=
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=en_US.utf8

Actual Result:

Fails with this error on line 31:
*** update-locale: Error: invalid locale settings: LC_ALL=en_US.UTF-8 LANG=en_GB.UTF-8

Quick Fix:

    template '/etc/locale.gen' do
      source 'locale.gen.erb'
    end
    execute "Updating Locales" do
      command "locale-gen en_US.UTF-8"
    end

See attached locale.txt = locale.gen.erb
locale.txt

cookbook version 2.1.0 does not set LC_ALL

Cookbook version

2.1.0

Chef-client version

14.3.37

Platform Details

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.5 LTS
Release:	16.04
Codename:	xenial

Scenario:

when i include in my cookbook the following

locale 'set locale' do
  lang 'en_US.utf8'
  lc_all 'en_US.utf8'
end

when i login to the converged node and look at the locale, the LC_ALL is not set

$ locale
LANG=en_US.utf8
LANGUAGE=
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=

$ cat /etc/default/locale
LANG=en_US.utf8

$ locale -a
C
C.UTF-8
en_US.utf8
POSIX

Steps to Reproduce:

include the code block above in your cookbook and converge the node

Expected Result:

LC_ALL should be set

Actual Result:

LC_ALL is not set

ChefSpec platform not supported?

Cookbook version

locale 2.0.1

Chef-client version

Chef Development Kit Version: 2.5.3
chef-client version: 13.8.5
delivery version: master (73ebb72a6c42b3d2ff5370c476be800fee7e5427)
berks version: 6.3.1
kitchen version: 1.20.0
inspec version: 1.51.21

Platform Details

MacOS

Scenario:

Have a simple spec like the following passing:

    it 'converges successfully' do
      expect { chef_run }.to_not raise_error
    end

Actual Result:

  1) xxx::default ubuntu converges successfully
     Failure/Error: expect { chef_run }.to_not raise_error

       expected no Exception, got #<RuntimeError: ubuntu platform not supported by the locale cookbook.> with backtrace:
         # /tmp/cookbooks/locale/recipes/default.rb:56:in `from_file'
         # /tmp/cookbooks/xxx/recipes/default.rb:25:in `from_file'
         # ./spec/unit/recipes/default_spec.rb:8:in `block (3 levels) in <top (required)>'
         # ./spec/unit/recipes/default_spec.rb:12:in `block (4 levels) in <top (required)>'
         # ./spec/unit/recipes/default_spec.rb:12:in `block (3 levels) in <top (required)>'
         # ./spec/spec_helper.rb:17:in `block (2 levels) in <top (required)>'
     # ./spec/unit/recipes/default_spec.rb:12:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:17:in `block (2 levels) in <top (required)>'

FATAL: NoMethodError: undefined method `[]' for nil:NilClass when locale attribute not defined in the node.

Hi,
Running your locale recipe I got this error (full output in the end)

[2013-05-23T05:52:37-04:00] FATAL: NoMethodError: undefined method `[]' for nil:NilClass

I worked it out declaring the locale in the node attributes

{
...
    "locale": {
                "lang" : "en_US.utf8"
        },
...
}

It worked that way but I am not sure why because the default attribute in the recipe is the same "en_US.utf8". I am including the recipe in my bp-debian-packages recipe, like

# Shell Dependencies
package "emacs"
package "dnsutils"
package "lynx"
package "sudo"
package "mutt"
package "screen"
package "tree"
package "build-essential"


#Postgres Dependencies
include_recipe "locale"
package "postgresql"
package "postgresql-client"
gem_package "pg"


Maybe there is some untested dependency on that attribute?

Thanks

Full output when it failed.

================================================================================
Recipe Compile Error in /tmp/chef-solo/site-cookbooks/bp-debian-packages/recipes/default.rb
================================================================================


NoMethodError
-------------
undefined method `[]' for nil:NilClass


Cookbook Trace:
---------------
  /tmp/chef-solo/cookbooks/locale/recipes/default.rb:27:in `block in from_file'
  /tmp/chef-solo/cookbooks/locale/recipes/default.rb:26:in `from_file'
  /tmp/chef-solo/site-cookbooks/bp-debian-packages/recipes/default.rb:33:in `from_file'


Relevant File Content:
----------------------
/tmp/chef-solo/cookbooks/locale/recipes/default.rb:

 20:  if platform?("ubuntu", "debian")
 21:
 22:    package "locales" do
 23:      action :install
 24:    end
 25:
 26:    execute "Update locale" do
 27>>     command "update-locale LANG=#{node[:locale][:lang]}"
 28:    end
 29:
 30:  end
 31:
 32:  if platform?("redhat", "centos", "fedora")
 33:
 34:    execute "Update locale" do
 35:      command "locale -a | grep ^#{node[:locale][:lang]}$ && sed -i 's|LANG=.*|LANG=#{node[:locale][:lang]}|' /etc/sysconfig/i18n"
 36:    end



[2013-05-23T05:52:37-04:00] ERROR: Running exception handlers
[2013-05-23T05:52:37-04:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-05-23T05:52:37-04:00] FATAL: Stacktrace dumped to /tmp/chef-solo/chef-stacktrace.out
[2013-05-23T05:52:37-04:00] FATAL: NoMethodError: undefined method `[]' for nil:NilClass
ERROR: RuntimeError: chef-solo failed. See output above.

The resource is executed each time on CentOS 7

Cookbook version

2.0.1

Chef-client version

13.6.4

Platform Details

CentOS 7

Scenario:

Steps to Reproduce:

Expected Result:

Avoid execution everytime chef-client run.

Actual Result:

locale setup is executed each time chef-client is running because Locale.up_to_date function is not detection the default quotas from CentOS 7:

# cat /etc/locale.conf
LANG="en_US.UTF-8"

Sugestions to fix:

Replace this line

locale.include?("LANG=#{lang}") &&

with

locale.match?("LANG=([\"']*)#{lang}([\"']*)") &&

or

(locale.include?("LANG=#{lang}") || locale.include?("LANG=\"#{lang}\"") || locale.include?("LANG='#{lang}'")) &&

Add resource for adding locales

It would be nice to have an LWRP for installing additional locales without setting them.

This would be useful when using phps setlocale, to format dates etc.

Request to change the LC_ALL default setting and add the possibility to unset LC_ALL.

Cookbook version

2.0.0

Chef-client version

12.17.44

Platform Details

ubuntu 16.04

Scenario:

I'm struggling with getting locale setting to my likings for a node.

The particular problem I have is to get Thunderbird on my Ubuntu 16.04 Desktop host showing dates in Swedish format, while having English(United States) as the preferred format.

I get the wanted behaviour when I have English(United States) as the preferred format in Ubuntu's System Settings...>Language Support>Language and have chosen Swedish in Settings...>Language Support>Regional Formats and unset LC_ALL (e.g. by removing it from /etc/default/locale).

It seems to me that the only way to "unset" LC_ALL, when using the locale cookbook, is to set the attribute locale['lc_all'] to " ". (Resulting in LC_ALL= rather than unsetting it.) .
Setting it to "" (or, I guess nil - have not tested) sets LC_ALL to locale['lang'] which defaults to "en_US.utf8".

At https://wiki.debian.org/Locale it is stated that "Using LC_ALL is strongly discouraged as it overrides everything. Please use it only when testing and never set it in a startup file.".

So, I wonder why the cookbook sets LC_ALL to locale['lang'], which defaults to "en_US.utf8". Wouldn't it be better to unset LC_ALL as default?

Also, I think that it would be good to be able to unset LC_ALL by e.g. setting the attribute locale['lc_all'] to nil.

Steps to Reproduce:

This is how I am currently installing the Swedish language and setting LC_ALL to empty in my recipe. I am using locale-gen 0.0.3:

node.default['localegen']['lang'] = ["en_US", "en_US.UTF-8", "sv_SE", "sv_SE.UTF-8"]
package 'language-pack-sv'
package 'language-pack-sv-base'
package 'language-pack-gnome-sv'
package 'language-pack-gnome-sv-base'
include_recipe 'locale-gen'
node.default['locale']['lc_all'] =  " "
include_recipe 'locale'

It gives the following environment setting:

$ env | grep LC_
LC_PAPER=sv_SE.UTF-8
LC_ADDRESS=sv_SE.UTF-8
LC_MONETARY=sv_SE.UTF-8
LC_NUMERIC=sv_SE.UTF-8
LC_ALL=
LC_TELEPHONE=sv_SE.UTF-8
LC_IDENTIFICATION=sv_SE.UTF-8
LC_MEASUREMENT=sv_SE.UTF-8
LC_TIME=sv_SE.UTF-8
LC_NAME=sv_SE.UTF-8

This gives the behaviour I want. Unsetting LC_ALL rather than setting it empty also gives the wanted behaviour.

Crash on ubuntu 14.04, file not found

On /var/lib/locales/supported.d/local I only have pt and en, not local

Recipe: <Dynamically Defined Resource>
  * ruby_block[add locale pt_BR] action run
================================================================================
Error executing action `run` on resource 'ruby_block[add locale pt_BR]'
================================================================================


ArgumentError
-------------
File '/var/lib/locales/supported.d/local' does not exist


Cookbook Trace:
---------------
/home/braulio/chef-solo/cookbooks-2/locales/providers/default.rb:79:in `new'
/home/braulio/chef-solo/cookbooks-2/locales/providers/default.rb:79:in `block (2 levels) in add_locale'


Resource Declaration:
---------------------
# In /home/braulio/chef-solo/cookbooks-2/locales/providers/default.rb

 77:   ruby_block "add locale #{locale}" do
 78:     block do
 79:       file = Chef::Util::FileEdit.new(node['locales']['locale_file'])
 80:       line = "#{high_locale(locale)} #{new_resource.charmap}"
 81:       file.insert_line_if_no_match(/^#{line}$/, line)
 82:       file.write_file
 83:     end
 84:     notifies :run, 'execute[locale-gen]', :immediate
 85:   end
 86: end



Compiled Resource:
# Declared in /home/braulio/chef-solo/cookbooks-2/locales/providers/default.rb:77:in `add_locale'

ruby_block("add locale pt_BR") do
  action "run"
  retries 0
  retry_delay 2
  guard_interpreter :default
  block_name "add locale pt_BR"
  cookbook_name :locales
  block #<Proc:0xb07901c@/home/braulio/chef-solo/cookbooks-2/locales/providers/default.rb:78>
end




Running handlers:
[2014-10-02T14:19:26-03:00] ERROR: Running exception handlers
Running handlers complete

Not working as expected on Debian (locale-gen is never called)

Cookbook version

2.0.0

Chef-client version

12.17.44

Platform Details

Debian 8.7.1

Scenario:

I want to use es_AR as the default locale

Steps to Reproduce:

Run this recipe with the following attributes:

node['locale']['lang'] = 'es_AR.utf8'
node['locale']['lc_all'] = 'es_AR.utf8'

Expected Result:

Locale successfully changed to es_AR.utf8

Actual Result:

I got the following error:

[2017-01-19T15:47:29+00:00] ERROR: execute[Update locale] (locale::default line 30) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '255'
---- Begin output of update-locale LANG=es_AR.utf8 LC_ALL=es_AR.utf8 ----
STDOUT:
STDERR: *** update-locale: Error: invalid locale settings:  LC_ALL=es_AR.utf8 LANG=es_AR.utf8
---- End output of update-locale LANG=es_AR.utf8 LC_ALL=es_AR.utf8 ----
Ran update-locale LANG=es_AR.utf8 LC_ALL=es_AR.utf8 returned 255

Aditional info

If I uncomment the following line on /etc/locale.gen and afterward execute locale-gen manually everything works as expected:

es_AR.UTF-8 UTF-8

So, probably the only thing that should be added to the recipe is the ability to change that file before executing locale-gen.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.