Issues with Template Files after upgrading to Chef 10.6


#1

So for some reason the following block of code stop working in Chef 10.6 on a ubuntu server:

template “/tmp/oxygen/properties.map” do
source "INT.properties.map.erb"
owner "root"
group "root"
mode 0644
variables(
:webname => node[:hostname],
:mysql_password => “#{mysql_pass}”,
:data_db => “DB_Host”,
:rs_db => “DB_HOST”,
:weblink => “URL”
)
only_if {environment == “int_environment”}
end

but if I change the following:

template “/tmp/properties.map” do

it starts working. Now the folder its uploaded too is created by chef:

FileUtils.mkdir_p("/tmp/oxygen/")

But on the system I am testing the recipe on I made the directory manually yet still it won’t upload the file. From the log it looks like it just skips over template like the if condition does not match but thats not the case. The weird thing is on another system that has 10.4 installed it works as expected. The only change has been upgraded to 10.6 on my personal system that I run knife on (and in turn the new systems get 10.6).

Zuhaib


#2

I see a bug in your code - environment should probably be node.chef_environment == “int_environment”?

Adam


Opscode, Inc.
Adam Jacob, Chief Customer Officer
T: (206) 619-7151 E: adam@opscode.com

On Dec 14, 2011, at 8:40 PM, Zuhaib Siddique wrote:

So for some reason the following block of code stop working in Chef 10.6 on a ubuntu server:

template “/tmp/oxygen/properties.map” do
source "INT.properties.map.erb"
owner "root"
group "root"
mode 0644
variables(
:webname => node[:hostname],
:mysql_password => “#{mysql_pass}”,
:data_db => “DB_Host”,
:rs_db => “DB_HOST”,
:weblink => “URL”
)
only_if {environment == “int_environment”}
end

but if I change the following:

template “/tmp/properties.map” do

it starts working. Now the folder its uploaded too is created by chef:

FileUtils.mkdir_p("/tmp/oxygen/")

But on the system I am testing the recipe on I made the directory manually yet still it won’t upload the file. From the log it looks like it just skips over template like the if condition does not match but thats not the case. The weird thing is on another system that has 10.4 installed it works as expected. The only change has been upgraded to 10.6 on my personal system that I run knife on (and in turn the new systems get 10.6).

Zuhaib


#3

Also - why are you doing FileUtils.mkdir_p instead of the directory resource?

Adam


Opscode, Inc.
Adam Jacob, Chief Customer Officer
T: (206) 619-7151 E: adam@opscode.com

On Dec 14, 2011, at 8:40 PM, Zuhaib Siddique wrote:

So for some reason the following block of code stop working in Chef 10.6 on a ubuntu server:

template “/tmp/oxygen/properties.map” do
source "INT.properties.map.erb"
owner "root"
group "root"
mode 0644
variables(
:webname => node[:hostname],
:mysql_password => “#{mysql_pass}”,
:data_db => “DB_Host”,
:rs_db => “DB_HOST”,
:weblink => “URL”
)
only_if {environment == “int_environment”}
end

but if I change the following:

template “/tmp/properties.map” do

it starts working. Now the folder its uploaded too is created by chef:

FileUtils.mkdir_p("/tmp/oxygen/")

But on the system I am testing the recipe on I made the directory manually yet still it won’t upload the file. From the log it looks like it just skips over template like the if condition does not match but thats not the case. The weird thing is on another system that has 10.4 installed it works as expected. The only change has been upgraded to 10.6 on my personal system that I run knife on (and in turn the new systems get 10.6).

Zuhaib


#4

Actually the environment variable is not the chef environment, its something set earlier up (this was used prior to Chef 10 and I have not converted over). I just decided to go with mkdir_p because its what I knew but even if I switch to directory it still does not make sense why its refusing to create the template in that directory but its ok in any other.

On Dec 14, 2011, at 8:47 PM, Adam Jacob wrote:

I see a bug in your code - environment should probably be node.chef_environment == “int_environment”?

Adam


Opscode, Inc.
Adam Jacob, Chief Customer Officer
T: (206) 619-7151 E: adam@opscode.com

On Dec 14, 2011, at 8:40 PM, Zuhaib Siddique wrote:

So for some reason the following block of code stop working in Chef 10.6 on a ubuntu server:

template “/tmp/oxygen/properties.map” do
source "INT.properties.map.erb"
owner "root"
group "root"
mode 0644
variables(
:webname => node[:hostname],
:mysql_password => “#{mysql_pass}”,
:data_db => “DB_Host”,
:rs_db => “DB_HOST”,
:weblink => “URL”
)
only_if {environment == “int_environment”}
end

but if I change the following:

template “/tmp/properties.map” do

it starts working. Now the folder its uploaded too is created by chef:

FileUtils.mkdir_p("/tmp/oxygen/")

But on the system I am testing the recipe on I made the directory manually yet still it won’t upload the file. From the log it looks like it just skips over template like the if condition does not match but thats not the case. The weird thing is on another system that has 10.4 installed it works as expected. The only change has been upgraded to 10.6 on my personal system that I run knife on (and in turn the new systems get 10.6).

Zuhaib


#5

On Wednesday, December 14, 2011 at 11:55 PM, Zuhaib Siddique wrote:

Actually the environment variable is not the chef environment, its something set earlier up (this was used prior to Chef 10 and I have not converted over). I just decided to go with mkdir_p because its what I knew but even if I switch to directory it still does not make sense why its refusing to create the template in that directory but its ok in any other.

Can you run chef with -ldebug and post the relevant section here? We don’t need all of it, just the part that shows this template resource.


Dan DeLeo


#6

Dan,

So the debug logs show that its skipping over the template because it claims that my only_if statement is false:

[Thu, 15 Dec 2011 20:09:22 +0000] DEBUG: Processing template[/tmp/oxygen/properties.map] on
[Thu, 15 Dec 2011 20:09:22 +0000] INFO: Processing template[/tmp/oxygen/properties.map] action create (gridiron-deploy::default line 46)
[Thu, 15 Dec 2011 20:09:22 +0000] DEBUG: Skipping template[/tmp/oxygen/properties.map] due to only_if ruby block

just one problem, if I change the path and NOTHING else it says this:

[Thu, 15 Dec 2011 20:17:11 +0000] DEBUG: Processing template[/tmp/properties.map] on
[Thu, 15 Dec 2011 20:17:11 +0000] INFO: Processing template[/tmp/properties.map] action create (gridiron-deploy::default line 46)

It makes no sense that the path would cause Chef to think the only_if statement is false. My next test is to pull the only_if statements.

Zuhaib

On Dec 15, 2011, at 8:34 AM, Daniel DeLeo wrote:

On Wednesday, December 14, 2011 at 11:55 PM, Zuhaib Siddique wrote:

Actually the environment variable is not the chef environment, its something set earlier up (this was used prior to Chef 10 and I have not converted over). I just decided to go with mkdir_p because its what I knew but even if I switch to directory it still does not make sense why its refusing to create the template in that directory but its ok in any other.

Can you run chef with -ldebug and post the relevant section here? We don’t need all of it, just the part that shows this template resource.


Dan DeLeo


#7

So I found the issue, it was in the past we abused the “only_if” statements for templates and it seems this was fine in 10.4 but 10.6 got more strict with Templates. So after some refactoring things are more happy. Its a bit annoying that things change on you jut by an upgrade but hey…

Zuhaib
On Dec 15, 2011, at 12:22 PM, Zuhaib Siddique wrote:

Dan,

So the debug logs show that its skipping over the template because it claims that my only_if statement is false:

[Thu, 15 Dec 2011 20:09:22 +0000] DEBUG: Processing template[/tmp/oxygen/properties.map] on
[Thu, 15 Dec 2011 20:09:22 +0000] INFO: Processing template[/tmp/oxygen/properties.map] action create (gridiron-deploy::default line 46)
[Thu, 15 Dec 2011 20:09:22 +0000] DEBUG: Skipping template[/tmp/oxygen/properties.map] due to only_if ruby block

just one problem, if I change the path and NOTHING else it says this:

[Thu, 15 Dec 2011 20:17:11 +0000] DEBUG: Processing template[/tmp/properties.map] on
[Thu, 15 Dec 2011 20:17:11 +0000] INFO: Processing template[/tmp/properties.map] action create (gridiron-deploy::default line 46)

It makes no sense that the path would cause Chef to think the only_if statement is false. My next test is to pull the only_if statements.

Zuhaib

On Dec 15, 2011, at 8:34 AM, Daniel DeLeo wrote:

On Wednesday, December 14, 2011 at 11:55 PM, Zuhaib Siddique wrote:

Actually the environment variable is not the chef environment, its something set earlier up (this was used prior to Chef 10 and I have not converted over). I just decided to go with mkdir_p because its what I knew but even if I switch to directory it still does not make sense why its refusing to create the template in that directory but its ok in any other.

Can you run chef with -ldebug and post the relevant section here? We don’t need all of it, just the part that shows this template resource.


Dan DeLeo


#8

On Thursday, December 15, 2011 at 8:17 PM, Zuhaib Siddique wrote:

So I found the issue, it was in the past we abused the “only_if” statements for templates

Can you explain what you were doing? Were you overwriting the only_if setting on the resource?

Its a bit annoying that things change on you jut by an upgrade but hey…

We strive to never break people with patch upgrades, so I’m bummed we didn’t meet that standard for your case. That said, we can’t catch every issue with automated testing and code review, so we rely on our community to test release candidates. If you’d like to help, you can join the chef-dev list to be notified when beta and RC versions are available for testing.

Zuhaib


Dan DeLeo


#9

Dan.

I fully understand that you can support all edge cases, trust me about it at our company we have a hard time QA’ing everything. Also the hack we did is not something I am proud about so it was a good thing it broke as it forced me to rewrite it the right way.

The hack was something like this:

template "/tmp/properties.map" do
  only_if do environment == "Webclient-INT" end
  source "INT.properties.map.erb"
  mode 0644
  owner "tomcat6"
  group "tomcat6"
        variables(
        <STUFF>
     	)
  end

template "/tmp/properties.map" do
  only_if do environment == "Webclient-QA" end
  source "QA.properties.map.erb"
  mode 0644
  owner "tomcat6"
  group "tomcat6"
variables(
) end and etc… As we would bring online new Environments we would add to this. Now I have collapsed it to a single template call and we set the source name somewhere else.

Zjuhaib
On Dec 16, 2011, at 9:28 AM, Daniel DeLeo wrote:

On Thursday, December 15, 2011 at 8:17 PM, Zuhaib Siddique wrote:

So I found the issue, it was in the past we abused the “only_if” statements for templates

Can you explain what you were doing? Were you overwriting the only_if setting on the resource?

Its a bit annoying that things change on you jut by an upgrade but hey…

We strive to never break people with patch upgrades, so I’m bummed we didn’t meet that standard for your case. That said, we can’t catch every issue with automated testing and code review, so we rely on our community to test release candidates. If you’d like to help, you can join the chef-dev list to be notified when beta and RC versions are available for testing.

Zuhaib


Dan DeLeo