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

missing node attributes #52

Closed
kmanohar1 opened this issue Nov 16, 2016 · 1 comment
Closed

missing node attributes #52

kmanohar1 opened this issue Nov 16, 2016 · 1 comment

Comments

@kmanohar1
Copy link

kmanohar1 commented Nov 16, 2016

Cookbook version

Latest

Chef-client version

12.15.19

Platform Details

Linux

Here is my code:
File ol_ohai_plugin.rb has the following content

Ohai.plugin(:ol_ohai_plugin) do
  provides "oci_ol_km"
  collect_data(:default) do
    oci_ol_km Mash.new
    oci_ol_km[:ipaddress]="127.0.0.1"
  end
end

File - recipes/ol_translator.rb

`require 'json'

ohai_plugin 'My Ohai Plugin' do
  name 'ol_ohai_plugin'
  path '/var/tmp'
end

puts "**********************************"
puts node[:oci_ol_km][:ipaddress]
puts "**********************************"

`
When I run this code from my workstation on a node 'node10', I am not seeing my node attributes populated in the node object under 'automatic'.

From my workstation, I run it as follows:
knife ssh ip_address_of_node_10 'chef-client'
Please let me know what am I missing

@tas50
Copy link
Contributor

tas50 commented Nov 16, 2016

I believe what you're running into is a compile time vs. converge time problem in your recipe. Chef runs in two different phases. The first is a compile time phase where Ruby is evaluated. The 2nd phase involves actually converging each of the resources. The puts statements are actually running before the plugin is installed since the puts statements happen in the compile phase. You can work around some of this by adding compile_time true to the ohai plugin, but also testing with puts is going to be problematic since it's running during compile time. For troubleshooting you might have a better time adding chef log resources to the recipe as those will execute during the converge.

A nice blog explaining the Chef run process:
https://coderanger.net/two-pass/

The log resource:
https://docs.chef.io/resource_log.html

@tas50 tas50 closed this as completed Nov 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants