Skip to content

Instantly share code, notes, and snippets.

@danielsdeleo
Created October 16, 2012 20:30
Show Gist options
  • Select an option

  • Save danielsdeleo/3901789 to your computer and use it in GitHub Desktop.

Select an option

Save danielsdeleo/3901789 to your computer and use it in GitHub Desktop.
Removing attribute surprises
chef > Chef::VERSION
=> "10.14.2"
### Hidden state
chef > i = node[:network][:interfaces] ; nil
=> nil
chef > i.en0.to_hash
=> {"addresses"=>{"20:c9:d0:45:45:63"=>{"family"=>"lladdr"}, "fe80::22c9:d0ff:fe45:4563"=>{"family"=>"inet6", "prefixlen"=>"64", "scope"=>"Link"}, "172.28.8.77"=>{"family"=>"inet", "netmask"=>"255.255.255.0", "broadcast"=>"172.28.8.255"}}, "mtu"=>"1500", "flags"=>["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], "type"=>"en", "number"=>"0", "encapsulation"=>"Ethernet", "arp"=>{"169.254.255.255"=>"0:22:d:11:4b:48", "172.28.8.1"=>"0:22:d:11:4b:48", "172.28.8.255"=>"ff:ff:ff:ff:ff:ff"}}
chef > i.en0.to_hash
ArgumentError: Attribute en0 is not defined!
from /Users/ddeleo/.rbcompile/apps/chef/chef-10.14.2/lib/chef/node/attribute.rb:428:in `method_missing'
from (irb):31
from /Users/ddeleo/.rbcompile/apps/chef/chef-10.14.2/lib/chef/shef.rb:73:in `block in start'
from /Users/ddeleo/.rbcompile/apps/chef/chef-10.14.2/lib/chef/shef.rb:72:in `catch'
from /Users/ddeleo/.rbcompile/apps/chef/chef-10.14.2/lib/chef/shef.rb:72:in `start'
from /Users/ddeleo/.rbcompile/apps/chef/chef-10.14.2/bin/shef:34:in `<top (required)>'
from /Users/ddeleo/.rbcompile/bin/shef:46:in `load'
from /Users/ddeleo/.rbcompile/bin/shef:46:in `<main>'
### Implicit Attribute setting:
chef > node.some_attribute?(:foo)
=> :foo
chef > node[:some_attribute?]
=> :foo
chef > Chef::VERSION
=> "11.0.0.alpha"
### No more hidden state:
chef > i = node[:network][:interfaces] ; nil
=> nil
chef > i.en0
=> {"addresses"=>{"20:c9:d0:45:45:63"=>{"family"=>"lladdr"}, "fe80::22c9:d0ff:fe45:4563"=>{"family"=>"inet6", "prefixlen"=>"64", "scope"=>"Link"}, "172.28.8.77"=>{"family"=>"inet", "netmask"=>"255.255.255.0", "broadcast"=>"172.28.8.255"}}, "mtu"=>"1500", "flags"=>["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], "type"=>"en", "number"=>"0", "encapsulation"=>"Ethernet", "arp"=>{"169.254.255.255"=>"0:22:d:11:4b:48", "172.28.8.1"=>"0:22:d:11:4b:48", "172.28.8.255"=>"ff:ff:ff:ff:ff:ff"}}
chef > i.en0
=> {"addresses"=>{"20:c9:d0:45:45:63"=>{"family"=>"lladdr"}, "fe80::22c9:d0ff:fe45:4563"=>{"family"=>"inet6", "prefixlen"=>"64", "scope"=>"Link"}, "172.28.8.77"=>{"family"=>"inet", "netmask"=>"255.255.255.0", "broadcast"=>"172.28.8.255"}}, "mtu"=>"1500", "flags"=>["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], "type"=>"en", "number"=>"0", "encapsulation"=>"Ethernet", "arp"=>{"169.254.255.255"=>"0:22:d:11:4b:48", "172.28.8.1"=>"0:22:d:11:4b:48", "172.28.8.255"=>"ff:ff:ff:ff:ff:ff"}}
### No surprise attribute creation:
chef > node.some_attribute?(:foo)
NoMethodError: Undefined node attribute or method `some_attribute?' on `node'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment