Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

['tomcat']['base_version'] is not getting overridden? #129

Closed
melezhik opened this issue Mar 5, 2015 · 5 comments
Closed

['tomcat']['base_version'] is not getting overridden? #129

melezhik opened this issue Mar 5, 2015 · 5 comments

Comments

@melezhik
Copy link

melezhik commented Mar 5, 2015

chef client versions afftected:

11.16.4 , 12.0.3

cookbook version

tomcat@0.17.3

node ohai info (platform):

$ ohai  | grep platform
  "platform": "centos",
  "platform_version": "6.5",
  "platform_family": "rhel",

How to reproduce:

cat metadat/default.rb

name             'test'
version          '0.1.0'
depends          'tomcat'

cat recipes/default.rb

 node.override['tomcat']['base_version'] = 7
 include_recipe "tomcat"

chef-client -l info -r test


Starting Chef Client, version 12.0.3
[2015-03-05T12:21:13+00:00] INFO: *** Chef 12.0.3 ***
[2015-03-05T12:21:13+00:00] INFO: Chef-client pid: 12094
[2015-03-05T12:21:14+00:00] INFO: Setting the run_list to [#<Chef::RunList::RunListItem:0x00000002436cd0 @version=nil, @type=:recipe, @name="test">] from CLI options
[2015-03-05T12:21:14+00:00] INFO: Run List is [recipe[test]]
[2015-03-05T12:21:14+00:00] INFO: Run List expands to [test]
[2015-03-05T12:21:14+00:00] INFO: Starting Chef Run for ********
[2015-03-05T12:21:14+00:00] INFO: Running start handlers
[2015-03-05T12:21:14+00:00] INFO: Start handlers complete.
[2015-03-05T12:21:14+00:00] INFO: HTTP Request Returned 404 Object Not Found: 
resolving cookbooks for run list: ["test"]
[2015-03-05T12:21:14+00:00] INFO: Loading cookbooks [yum@3.5.2, yum-epel@0.6.0, chef-sugar@2.5.0, openssl@2.0.2, java@1.29.0, tomcat@0.17.3, test@0.1.0]
Synchronizing Cookbooks:
  - yum-epel
  - yum
  - openssl
  - chef-sugar
  - java
  - tomcat
  - test
Compiling Cookbooks...
Converging 4 resources
Recipe: yum-epel::default
  * yum_repository[epel] action create[2015-03-05T12:21:14+00:00] INFO: Processing yum_repository[epel] action create (yum-epel::default line 22)

    * template[/etc/yum.repos.d/epel.repo] action create[2015-03-05T12:21:14+00:00] INFO: Processing template[/etc/yum.repos.d/epel.repo] action create (/var/chef/cache/cookbooks/yum/providers/repository.rb line 39)
 (up to date)
    * execute[yum-makecache-epel] action nothing[2015-03-05T12:21:14+00:00] INFO: Processing execute[yum-makecache-epel] action nothing (/var/chef/cache/cookbooks/yum/providers/repository.rb line 55)
 (skipped due to action :nothing)
    * ruby_block[yum-cache-reload-epel] action nothing[2015-03-05T12:21:14+00:00] INFO: Processing ruby_block[yum-cache-reload-epel] action nothing (/var/chef/cache/cookbooks/yum/providers/repository.rb line 62)
 (skipped due to action :nothing)
     (up to date)
Recipe: tomcat::default
  * yum_package[tomcat6] action install

I just wonder why tomcat6 package gets installed? I expect according to the following code , i should be `tomcat' package ?

cat tomcat/attributes/default.rb :

default['tomcat']['base_version'] = 6
...
...
...
...

case node['platform_family']

when 'rhel', 'fedora'
  suffix = node['tomcat']['base_version'].to_i < 7 ? node['tomcat']['base_version'] : ""
  ....
  default['tomcat']['packages'] = ["tomcat#{suffix}"]
@melezhik melezhik changed the title ['tomcat']['base_version'] is not get overriden? ['tomcat']['base_version'] is not getting overridden? Mar 5, 2015
@marc-
Copy link

marc- commented Mar 11, 2015

This cookbook needs refactoring. Please see #89, #102 and especially this comment.

@melezhik
Copy link
Author

This cookbook needs refactoring

Thank you. When you are going to fix this?

@marc-
Copy link

marc- commented Mar 11, 2015

You better ask @someara or @jtimberman .

gsaslis pushed a commit to gsaslis/tomcat that referenced this issue Oct 12, 2015
There are several issues that stem from this very root cause: sous-chefs#89, sous-chefs#102, sous-chefs#129, sous-chefs#148 and sous-chefs#174. I've moved all derived attributes into a helper method that gets evaluated at recipe run time, so that the overriden values are taken into account, regardless of how they've been overriden (even from another cookbook's attributes).
tl;dr
# Any cookbook attribute that uses the value of another attribute to calculate its own value (derived)
# should be included in the new libraries/helper method, so that the calculation of the value takes place at runtime of the recipe.
# The reason is simple: Due to how attribute precedence works in Chef, when an attribute is overriden, it is not always
# the case that the derived attributes will use the correct value of the original attribute to calculate their own.
# This depends on how the attribute has been overriden (cookbook attributes, role, environment, etc.)
# See [this](https://christinemdraper.wordpress.com/2014/10/06/avoiding-the-possible-pitfalls-of-derived-attributes/) for a detailed explanation.
gsaslis pushed a commit to gsaslis/tomcat that referenced this issue Oct 12, 2015
There are several issues that stem from this very root cause: sous-chefs#89, sous-chefs#102, sous-chefs#129, sous-chefs#148 and sous-chefs#174. I've moved all derived attributes into a helper method that gets evaluated at recipe run time, so that the overriden values are taken into account, regardless of how they've been overriden (even from another cookbook's attributes).
tl;dr
# Any cookbook attribute that uses the value of another attribute to calculate its own value (derived)
# should be included in the new libraries/helper method, so that the calculation of the value takes place at runtime of the recipe.
# The reason is simple: Due to how attribute precedence works in Chef, when an attribute is overriden, it is not always
# the case that the derived attributes will use the correct value of the original attribute to calculate their own.
# This depends on how the attribute has been overriden (cookbook attributes, role, environment, etc.)
# See [this](https://christinemdraper.wordpress.com/2014/10/06/avoiding-the-possible-pitfalls-of-derived-attributes/) for a detailed explanation.
@tas50
Copy link
Contributor

tas50 commented Feb 25, 2016

First off I'm very sorry that it's taken so long to get back to you on this issue. For a significant period of time there was no active Chef Software Inc. maintainer for this repository and things languished. We're now actively maintaining this cookbook again, and as part of that I've rewritten the cookbook with new custom resources for installing Tomcat from Apache Org sources. This will ship in an upcoming 2.0 release and then we'll remove the existing recipes and providers in a future 3.X release. With those new providers I believe the need for this change goes away so I'm going to close this out. I encourage you to give the new providers a try and let me know if we can tackle more Tomcat management without the attributes bloat the current code suffers from. They're on the master branch and once the documentation and testing improves a bit they'll be released as a 2.0 cookbook.

@tas50 tas50 closed this as completed Feb 25, 2016
@lock
Copy link

lock bot commented May 5, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants