You have to do it in the action block, or rather inside a method of the provider class which is what #action creates.
--Noah
On Dec 24, 2013, at 9:10 PM, Christopher Armstrong < "> > wrote:
> Hmmm... maybe I need to put it in the library after all?
>
> NameError
> ---------
> undefined local variable or method `node' for #<Class:0x00000003117670>
>
>
> Cookbook Trace:
> ---------------
> /tmp/kitchen/cookbooks/java/providers/alternatives.rb:20:in `class_from_file'
>
>
> Relevant File Content:
> ----------------------
> /tmp/kitchen/cookbooks/java/providers/alternatives.rb:
>
> 13: # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> 14: # See the License for the specific language governing permissions and
> 15: # limitations under the License.
> 16:
> 17: require 'chef/mixin/shell_out'
> 18: include Chef::Mixin::ShellOut
> 19:
> 20>> alternatives_cmd = node['platform_family'] == 'rhel' ? 'alternatives' : 'update-alternatives'
> 21:
> 22: action :set do
> 23: if new_resource.bin_cmds
> 24: new_resource.bin_cmds.each do |cmd|
> 25:
> 26: bin_path = "/usr/bin/#{cmd}"
> 27: alt_path = "#{new_resource.java_location}/bin/#{cmd}"
> 28: priority = new_resource.priority
> 29:
>
>
>
> On Tue, Dec 24, 2013 at 8:34 PM, Christopher Armstrong < "> > wrote:
> Cool. Thanks Julian!
>
>
> On Tue, Dec 24, 2013 at 5:41 PM, Julian C. Dunn < "> > wrote:
> Hi Chris,
>
> Providers do have access to the node object, but you must refer to it
> directly e.g. node['platform_family'] . I don't believe the syntactic
> sugar of platform_family? is available.
>
> In library context you don't have access to the node object, so you
> can either pass it in on object initialization (e.g.
> https://github.com/socrata-cookbooks/java/blob/master/libraries/helpers.rb#L27)
> or passing parameters on method invocation.
>
> - Julian
>
> On Tue, Dec 24, 2013 at 2:14 PM, Christopher Armstrong
> < "> > wrote:
> > Ohai Chefs,
> >
> > I'm doing some Christmas Eve hacking, and I think I'm not approaching
> > something properly.
> >
> > Here is what I'm trying to do:
> > https://github.com/socrata-cookbooks/java/pull/111/files
> >
> > Essentially, I need to conditionalize code in a provider based on the node's
> > platform_family, but I don't believe I have access to the node objects or
> > methods within a provider. I could pass it in as a parameter, but that seems
> > clunky - the user of the provider shouldn't care about this detail. It's
> > something I want to abstract.
> >
> > Could someone point me in the right direction? I still get confused about
> > what Chef methods are available in recipes, libraries, providers, etc.
> >
> > Happy Holidays!
> >
> > Chris
>
>
>
> --
> [ Julian C. Dunn < "> > * Sorry, I'm ]
> [ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
> [ gopher://sdf.org/1/users/keymaker/ * compliant! ]
> [ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]
>
>
Archive powered by MHonArc 2.6.16.