Created
September 11, 2012 04:29
-
-
Save jtimberman/3695966 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chef | |
class Recipe | |
def skip_unsupported_platform | |
unless supported_platform? | |
Chef::Log.info("Unsupported platform #{node[:platform]} in #{cookbook_name}::#{recipe_name}, skipping recipe") | |
Chef::Log.debug("You said to skip unsupported platforms in #{cookbook_name}::#{recipe_name}") | |
Chef::Log.debug("and #{node['platform']} is unsupported by cookbook #{cookbook_name}. Update the cookbook's metadata") | |
Chef::Log.debug("if this is a supported platform, or remove #{cookbook_name}::#{recipe_name} from the node.") | |
end | |
end | |
def supported_platform? | |
run_context.cookbook_collection[cookbook_name].metadata.platforms.include?(node['platform']) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this at the top of a recipe if you want to enforce that it should only be run on | |
# platforms that are supported per the cookbook's metadata | |
return if skip_unsupported_platform | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hat tip to Alex Howells and Jay Feldblum for the run_context.cookbook_collection reminder for inspecting cookbook metadata.