Issues with Locale on Remote Client Node when running knife ssh: chef-client for Ubuntu 12.04 and chef 10 or chef 11

Currently I’m using chef 11 (just upgraded, hoping the problem would go away
but it hasn’t!)

So here’s my problem.

When I type the command “locale” on my ubuntu machine the default output I get
is the following:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Assume that I have a cook book that will write a locale to a temp file in a
recipe and cookbook

knife node run_list add server1 recipe[writelocale]

the following is the contents of the recipe/writelocale.rb

execute “locale” do
command "locale >> /tmp/locale.txt"
end

When I run this command

knife ssh name:server1 -x root -P password1 -a ipaddress “sudo -i chef-client”

to run a recipe remotely I always end up with this.

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=

I’m guessing it has something to do with the shell or how chef-server is
causing the remote ssh shell to execute. I only thing I can think of there is
some chef process whether it’s RabbitMQ or something else that is changing the
default shell locale to C vs UTT-8. I’ve tried numerous things, including
trying to set the LC_TYPE=“en_US.UTF-8” but I can’t seem to do it, the locale
always default to C. This is particularly a problem when I try to install
things like Postgresql, since I end up with the following instead of what I
actually need.

What I should See

List of databases
Name | Owner | Encoding | Collate | Ctype | Access
privileges
-----------±---------±---------±------------±------------±----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres

When I remote and run apt-get install -y postgresql-server-dev-9.1

		   List of databases

Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------±---------±----------±--------±------±----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres

I’ve been stuck on this issue for a few days now seems trivial at first but
it’s become and issue since it affects what packages I can install with the
Proper Locale.

Please help thanks!

On Friday, April 26, 2013 at 1:27 AM, harryyeh@cometcomputing.com wrote:

Currently I'm using chef 11 (just upgraded, hoping the problem would go away
but it hasn't!)

So here's my problem.

When I type the command "locale" on my ubuntu machine the default output I get
is the following:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Assume that I have a cook book that will write a locale to a temp file in a
recipe and cookbook

knife node run_list add server1 recipe[writelocale]

the following is the contents of the recipe/writelocale.rb

execute "locale" do
command "locale >> /tmp/locale.txt"
end

This is a tricky one. The underlying mixlib-shellout library that Chef uses to run commands sets the locale to "C" to avoid encoding issues and get consistent output from localized programs (Chef has to parse output from many commands and this doesn't work if you unexpectedly get Spanish output).

This is documented in the code here: mixlib-shellout/lib/mixlib/shellout.rb at master · chef/mixlib-shellout · GitHub

I think you should be able to add environment "LC_ALL" => nil to your execute command to override this.

HTH,

--
Daniel DeLeo

Actually I tried setting the environment and overriding it but it doesn't
work

I actually try to set the environment

On Fri, Apr 26, 2013 at 8:28 AM, Daniel DeLeo dan@kallistec.com wrote:

On Friday, April 26, 2013 at 1:27 AM, harryyeh@cometcomputing.com wrote:

Currently I'm using chef 11 (just upgraded, hoping the problem would go
away
but it hasn't!)

So here's my problem.

When I type the command "locale" on my ubuntu machine the default output I
get
is the following:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Assume that I have a cook book that will write a locale to a temp file in a
recipe and cookbook

knife node run_list add server1 recipe[writelocale]

the following is the contents of the recipe/writelocale.rb

execute "locale" do
command "locale >> /tmp/locale.txt"
end

This is a tricky one. The underlying mixlib-shellout library that Chef
uses to run commands sets the locale to "C" to avoid encoding issues and
get consistent output from localized programs (Chef has to parse output
from many commands and this doesn't work if you unexpectedly get Spanish
output).

This is documented in the code here:
mixlib-shellout/lib/mixlib/shellout.rb at master · chef/mixlib-shellout · GitHub

I think you should be able to add environment "LC_ALL" => nil to your
execute command to override this.

HTH,

--
Daniel DeLeo

--
Harry Yeh
CEO / CTO
Comet Computing
(604)304-1603

Web: http://www.cometcomputing.com
Me: http://www.linkedin.com/in/harryyeh
Twitter: http://twitter.com/harryyeh
Facebook: Facebook

Confidentiality Notice:

This electronic mail transmission and any accompanying attachments contain
confidential information intended only for the use of the individual or
entity named above. Any dissemination, distribution, copying or action
taken in reliance on the contents of this communication by anyone other
than the intended recipient is strictly prohibited. If you have received
this communication in error please immediately delete the E-mail and notify
the sender at the above E-mail address.

On Friday, April 26, 2013 at 10:26 AM, Harry Yeh wrote:

Actually I tried setting the environment and overriding it but it doesn't work

I actually try to set the environment

Can you share the exact code you used and the result?

--
Daniel DeLeo

Ohai, Chefs,

I have been trying to use a test-driven development method for baking Chef recipes and have been having good success with chefspec and minitest-chef-handler. However, one area that currently is difficult to test are templates.

I am looking for a way to get the output of erb templates, correctly substituting in node attributes (e.g. have a <%= node[:something] %> and want to get it to substitute correctly). So far, I haven’t found a solution.

I was wondering if anyone has a solution to this?

Otherwise, I am considering working on one, perhaps using Fauxhai to mock for node attribute substitution .

Thanks a lot,
Carlton

Carlton,

You can specify attributes for a test scenario in .kitchen.yml if you
are using test-kitchen. Review
https://github.com/opscode/test-kitchen/blob/1.0/README.md and scan down
to The Kitchen YAML Format. chef-rvm uses attributes so it maybe
worth a review. GitHub - sous-chefs/rvm: Development repository for the rvm cookbook

Hope that helps

Scott
On 4/26/13 11:32 AM, Carlton Stedman wrote:

Ohai, Chefs,

I have been trying to use a test-driven development method for baking
Chef recipes and have been having good success with chefspec and
minitest-chef-handler. However, one area that currently is difficult
to test are templates.

I am looking for a way to get the output of erb templates, correctly
substituting in node attributes (e.g. have a <%= node[:something] %>
and want to get it to substitute correctly). So far, I haven't found a
solution.

I was wondering if anyone has a solution to this?

Otherwise, I am considering working on one, perhaps using Fauxhai to
mock for node attribute substitution.

Thanks a lot,
Carlton
!DSPAM:517ac843209751804284693!

Check out fauxhai for combination with chefspec -- sethvargo project;
contains huge amounts of mock ohai data -- may be useful.

Cheers,

AJ

On 27 April 2013 06:37, Scott M. Likens scott@likens.us wrote:

Carlton,

You can specify attributes for a test scenario in .kitchen.yml if you are
using test-kitchen. Review
https://github.com/opscode/test-kitchen/blob/1.0/README.md and scan down to
The Kitchen YAML Format. chef-rvm uses attributes so it maybe worth a
review. GitHub - sous-chefs/rvm: Development repository for the rvm cookbook

Hope that helps

Scott

On 4/26/13 11:32 AM, Carlton Stedman wrote:

Ohai, Chefs,

I have been trying to use a test-driven development method for baking Chef
recipes and have been having good success with chefspec and
minitest-chef-handler. However, one area that currently is difficult to test
are templates.

I am looking for a way to get the output of erb templates, correctly
substituting in node attributes (e.g. have a <%= node[:something] %> and
want to get it to substitute correctly). So far, I haven't found a solution.

I was wondering if anyone has a solution to this?

Otherwise, I am considering working on one, perhaps using Fauxhai to mock
for node attribute substitution.

Thanks a lot,
Carlton
!DSPAM:517ac843209751804284693!

Tried thia

execute "locale" do
command "
LC_CTYPE=en_US.UTF-8
locale >> /tmp/locale.txt"
end

that even shows up as

LC_CTYPE=C

You can try it

On Fri, Apr 26, 2013 at 1:27 AM, harryyeh@cometcomputing.com wrote:

Currently I'm using chef 11 (just upgraded, hoping the problem would go
away
but it hasn't!)

So here's my problem.

When I type the command "locale" on my ubuntu machine the default output I
get
is the following:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Assume that I have a cook book that will write a locale to a temp file in a
recipe and cookbook

knife node run_list add server1 recipe[writelocale]

the following is the contents of the recipe/writelocale.rb

execute "locale" do
command "locale >> /tmp/locale.txt"
end

When I run this command

knife ssh name:server1 -x root -P password1 -a ipaddress "sudo -i
chef-client"

to run a recipe remotely I always end up with this.

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=

I'm guessing it has something to do with the shell or how chef-server is
causing the remote ssh shell to execute. I only thing I can think of there
is
some chef process whether it's RabbitMQ or something else that is changing
the
default shell locale to C vs UTT-8. I've tried numerous things, including
trying to set the LC_TYPE="en_US.UTF-8" but I can't seem to do it, the
locale
always default to C. This is particularly a problem when I try to install
things like Postgresql, since I end up with the following instead of what I
actually need.

What I should See

List of databases
Name | Owner | Encoding | Collate | Ctype | Access
privileges

-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres

When I remote and run apt-get install -y postgresql-server-dev-9.1

                       List of databases

Name | Owner | Encoding | Collate | Ctype | Access privileges

-----------+----------+-----------+---------+-------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres
+
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres
+
| | | | | postgres=CTc/postgres

I've been stuck on this issue for a few days now seems trivial at first but
it's become and issue since it affects what packages I can install with the
Proper Locale.

Please help thanks!

--
Harry Yeh
CEO / CTO
Comet Computing
(604)304-1603

Web: http://www.cometcomputing.com
Me: http://www.linkedin.com/in/harryyeh
Twitter: http://twitter.com/harryyeh
Facebook: Facebook

Confidentiality Notice:

This electronic mail transmission and any accompanying attachments contain
confidential information intended only for the use of the individual or
entity named above. Any dissemination, distribution, copying or action
taken in reliance on the contents of this communication by anyone other
than the intended recipient is strictly prohibited. If you have received
this communication in error please immediately delete the E-mail and notify
the sender at the above E-mail address.

Use the 'environment' parameter to the execute resource to set
environment variables, i.e;

execute 'locale'
environment 'LC_CTYPE' => 'en_US.UTF-8'
command 'locale | tee /tmp/locale.txt'
end

Cheers,

AJ

On 27 April 2013 09:59, Harry Yeh harryyeh@cometcomputing.com wrote:

Tried thia

execute "locale" do
command "
LC_CTYPE=en_US.UTF-8
locale >> /tmp/locale.txt"
end

that even shows up as

LC_CTYPE=C

You can try it

On Fri, Apr 26, 2013 at 1:27 AM, harryyeh@cometcomputing.com wrote:

Currently I'm using chef 11 (just upgraded, hoping the problem would go
away
but it hasn't!)

So here's my problem.

When I type the command "locale" on my ubuntu machine the default output I
get
is the following:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Assume that I have a cook book that will write a locale to a temp file in
a
recipe and cookbook

knife node run_list add server1 recipe[writelocale]

the following is the contents of the recipe/writelocale.rb

execute "locale" do
command "locale >> /tmp/locale.txt"
end

When I run this command

knife ssh name:server1 -x root -P password1 -a ipaddress "sudo -i
chef-client"

to run a recipe remotely I always end up with this.

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=

I'm guessing it has something to do with the shell or how chef-server is
causing the remote ssh shell to execute. I only thing I can think of there
is
some chef process whether it's RabbitMQ or something else that is changing
the
default shell locale to C vs UTT-8. I've tried numerous things, including
trying to set the LC_TYPE="en_US.UTF-8" but I can't seem to do it, the
locale
always default to C. This is particularly a problem when I try to install
things like Postgresql, since I end up with the following instead of what
I
actually need.

What I should See

List of databases
Name | Owner | Encoding | Collate | Ctype | Access
privileges

-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres

When I remote and run apt-get install -y postgresql-server-dev-9.1

                       List of databases

Name | Owner | Encoding | Collate | Ctype | Access privileges

-----------+----------+-----------+---------+-------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres
+
| | | | |
postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres
+
| | | | |
postgres=CTc/postgres

I've been stuck on this issue for a few days now seems trivial at first
but
it's become and issue since it affects what packages I can install with
the
Proper Locale.

Please help thanks!

--
Harry Yeh
CEO / CTO
Comet Computing
(604)304-1603

Web: http://www.cometcomputing.com
Me: http://www.linkedin.com/in/harryyeh
Twitter: http://twitter.com/harryyeh
Facebook: Facebook

Confidentiality Notice:

This electronic mail transmission and any accompanying attachments contain
confidential information intended only for the use of the individual or
entity named above. Any dissemination, distribution, copying or action taken
in reliance on the contents of this communication by anyone other than the
intended recipient is strictly prohibited. If you have received this
communication in error please immediately delete the E-mail and notify the
sender at the above E-mail address.

On Friday, April 26, 2013 at 3:01 PM, AJ Christensen wrote:

Use the 'environment' parameter to the execute resource to set
environment variables, i.e;

execute 'locale'
environment 'LC_CTYPE' => 'en_US.UTF-8'
command 'locale | tee /tmp/locale.txt'
end

Cheers,

AJ
mixlib-shellout cares in particular about LC_ALL. Given this code:

execute 'locale' do
environment 'LC_ALL' => nil
command 'locale | tee /tmp/locale.txt'
end

running chef-apply locale.rb, I get:

cat locale.txt
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=

--
Daniel DeLeo

On 27 April 2013 09:59, Harry Yeh <harryyeh@cometcomputing.com (mailto:harryyeh@cometcomputing.com)> wrote:

Tried thia

execute "locale" do
command "
LC_CTYPE=en_US.UTF-8
locale >> /tmp/locale.txt"
end

that even shows up as

LC_CTYPE=C

You can try it

On Fri, Apr 26, 2013 at 1:27 AM, <harryyeh@cometcomputing.com (mailto:harryyeh@cometcomputing.com)> wrote:

Currently I'm using chef 11 (just upgraded, hoping the problem would go
away
but it hasn't!)

So here's my problem.

When I type the command "locale" on my ubuntu machine the default output I
get
is the following:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Assume that I have a cook book that will write a locale to a temp file in
a
recipe and cookbook

knife node run_list add server1 recipe[writelocale]

the following is the contents of the recipe/writelocale.rb

execute "locale" do
command "locale >> /tmp/locale.txt"
end

When I run this command

knife ssh name:server1 -x root -P password1 -a ipaddress "sudo -i
chef-client"

to run a recipe remotely I always end up with this.

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=

I'm guessing it has something to do with the shell or how chef-server is
causing the remote ssh shell to execute. I only thing I can think of there
is
some chef process whether it's RabbitMQ or something else that is changing
the
default shell locale to C vs UTT-8. I've tried numerous things, including
trying to set the LC_TYPE="en_US.UTF-8" but I can't seem to do it, the
locale
always default to C. This is particularly a problem when I try to install
things like Postgresql, since I end up with the following instead of what
I
actually need.

What I should See

List of databases
Name | Owner | Encoding | Collate | Ctype | Access
privileges

-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres

When I remote and run apt-get install -y postgresql-server-dev-9.1

List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges

-----------+----------+-----------+---------+-------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres
+
| | | | |
postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres
+
| | | | |
postgres=CTc/postgres

I've been stuck on this issue for a few days now seems trivial at first
but
it's become and issue since it affects what packages I can install with
the
Proper Locale.

Please help thanks!

--
Harry Yeh
CEO / CTO
Comet Computing
(604)304-1603

Web: http://www.cometcomputing.com
Me: http://www.linkedin.com/in/harryyeh
Twitter: http://twitter.com/harryyeh
Facebook: Facebook

Confidentiality Notice:

This electronic mail transmission and any accompanying attachments contain
confidential information intended only for the use of the individual or
entity named above. Any dissemination, distribution, copying or action taken
in reliance on the contents of this communication by anyone other than the
intended recipient is strictly prohibited. If you have received this
communication in error please immediately delete the E-mail and notify the
sender at the above E-mail address.

My mistake, I only meant to correct the error WRT: environment parameter.

Cheers,

AJ

On 27 April 2013 10:09, Daniel DeLeo dan@kallistec.com wrote:

On Friday, April 26, 2013 at 3:01 PM, AJ Christensen wrote:

Use the 'environment' parameter to the execute resource to set
environment variables, i.e;

execute 'locale'
environment 'LC_CTYPE' => 'en_US.UTF-8'
command 'locale | tee /tmp/locale.txt'
end

Cheers,

AJ

mixlib-shellout cares in particular about LC_ALL. Given this code:

execute 'locale' do
environment 'LC_ALL' => nil
command 'locale | tee /tmp/locale.txt'
end

running chef-apply locale.rb, I get:

cat locale.txt
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=

--
Daniel DeLeo

On 27 April 2013 09:59, Harry Yeh harryyeh@cometcomputing.com wrote:

Tried thia

execute "locale" do
command "
LC_CTYPE=en_US.UTF-8
locale >> /tmp/locale.txt"
end

that even shows up as

LC_CTYPE=C

You can try it

On Fri, Apr 26, 2013 at 1:27 AM, harryyeh@cometcomputing.com wrote:

Currently I'm using chef 11 (just upgraded, hoping the problem would go
away
but it hasn't!)

So here's my problem.

When I type the command "locale" on my ubuntu machine the default output I
get
is the following:

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

Assume that I have a cook book that will write a locale to a temp file in
a
recipe and cookbook

knife node run_list add server1 recipe[writelocale]

the following is the contents of the recipe/writelocale.rb

execute "locale" do
command "locale >> /tmp/locale.txt"
end

When I run this command

knife ssh name:server1 -x root -P password1 -a ipaddress "sudo -i
chef-client"

to run a recipe remotely I always end up with this.

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=

I'm guessing it has something to do with the shell or how chef-server is
causing the remote ssh shell to execute. I only thing I can think of there
is
some chef process whether it's RabbitMQ or something else that is changing
the
default shell locale to C vs UTT-8. I've tried numerous things, including
trying to set the LC_TYPE="en_US.UTF-8" but I can't seem to do it, the
locale
always default to C. This is particularly a problem when I try to install
things like Postgresql, since I end up with the following instead of what
I
actually need.

What I should See

List of databases
Name | Owner | Encoding | Collate | Ctype | Access
privileges

-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres

When I remote and run apt-get install -y postgresql-server-dev-9.1

List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges

-----------+----------+-----------+---------+-------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres
+
| | | | |
postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres
+
| | | | |
postgres=CTc/postgres

I've been stuck on this issue for a few days now seems trivial at first
but
it's become and issue since it affects what packages I can install with
the
Proper Locale.

Please help thanks!

--
Harry Yeh
CEO / CTO
Comet Computing
(604)304-1603

Web: http://www.cometcomputing.com
Me: http://www.linkedin.com/in/harryyeh
Twitter: http://twitter.com/harryyeh
Facebook: Facebook

Confidentiality Notice:

This electronic mail transmission and any accompanying attachments contain
confidential information intended only for the use of the individual or
entity named above. Any dissemination, distribution, copying or action taken
in reliance on the contents of this communication by anyone other than the
intended recipient is strictly prohibited. If you have received this
communication in error please immediately delete the E-mail and notify the
sender at the above E-mail address.

On Friday, April 26, 2013 at 3:43 PM, AJ Christensen wrote:

My mistake, I only meant to correct the error WRT: environment parameter.

Cheers,

AJ

No worries :slight_smile:

--
Daniel DeLeo

I shall try this

I should have used this mailing list Sooner it would have saved me a lot of time Doh!

Harry Yeh
Sent from my iPhone 5
http://www.linkedin.com/in/harryyeh
follow me on twitter @harryyeh

On 2013-04-26, at 3:45 PM, Daniel DeLeo dan@kallistec.com wrote:

On Friday, April 26, 2013 at 3:43 PM, AJ Christensen wrote:

My mistake, I only meant to correct the error WRT: environment parameter.

Cheers,

AJ

No worries :slight_smile:

--
Daniel DeLeo

Btw, as of ChefSpec 1.0, Fauxhai is part of ChefSpec.

See GitHub - chefspec/chefspec: Write RSpec examples and generate coverage reports for Chef recipes!

-Mathias

On Fri, Apr 26, 2013 at 11:33 PM, AJ Christensen aj@junglist.gen.nz wrote:

Check out fauxhai for combination with chefspec -- sethvargo project;
contains huge amounts of mock ohai data -- may be useful.

Cheers,

AJ

On 27 April 2013 06:37, Scott M. Likens scott@likens.us wrote:

Carlton,

You can specify attributes for a test scenario in .kitchen.yml if you are
using test-kitchen. Review
https://github.com/opscode/test-kitchen/blob/1.0/README.md and scan down to
The Kitchen YAML Format. chef-rvm uses attributes so it maybe worth a
review. GitHub - sous-chefs/rvm: Development repository for the rvm cookbook

Hope that helps

Scott

On 4/26/13 11:32 AM, Carlton Stedman wrote:

Ohai, Chefs,

I have been trying to use a test-driven development method for baking Chef
recipes and have been having good success with chefspec and
minitest-chef-handler. However, one area that currently is difficult to test
are templates.

I am looking for a way to get the output of erb templates, correctly
substituting in node attributes (e.g. have a <%= node[:something] %> and
want to get it to substitute correctly). So far, I haven't found a solution.

I was wondering if anyone has a solution to this?

Otherwise, I am considering working on one, perhaps using Fauxhai to mock
for node attribute substitution.

Thanks a lot,
Carlton
!DSPAM:517ac843209751804284693!

--
My blog: http://mlafeldt.github.com
My code: mlafeldt (Mathias Lafeldt) · GitHub
My tweets: https://twitter.com/mlafeldt