Skip to content

Instantly share code, notes, and snippets.

@nathanhoel
Created March 24, 2016 15:09
Show Gist options
  • Save nathanhoel/fd6f0b26e3e7d649d37c to your computer and use it in GitHub Desktop.
Save nathanhoel/fd6f0b26e3e7d649d37c to your computer and use it in GitHub Desktop.
Chef evaluation timing and variable scope within ruby_block resources
the_test = 1
Chef::Log.info("The test is #{the_test}")
ruby_block "first" do
block do
Chef::Log.info("(first block) The test is #{the_test}")
the_test = 2
end
end
ruby_block "second" do
block do
Chef::Log.info("(second block) The test is #{the_test}")
the_test = 3
end
end
# Output:
# The test is 1
# (first block) The test is 1
# (second block) The test is 2
# This shows that the contents of the 'block' attribute are evaluated during the converge step.
# Normally most attributes are evaluated before the converge step.
# Also variables defined outside the ruby_block resource are available inside the 'ruby_block' 'block' attribute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment