Created
September 22, 2015 15:34
-
-
Save sirosen/e1a7a831d26bf461c438 to your computer and use it in GitHub Desktop.
ChefAttributesByTagsDemo
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
default['cookbook']['services']['service1']['source_url'] = 'https://example.com/s1' | |
default['cookbook']['services']['service2']['source_url'] = 'https://example.com/s2' | |
default['cookbook']['services']['service3']['source_url'] = 'https://example.com/s3' | |
default['cookbook']['base_service_set'] = [] | |
default['cookbook']['service_set'] = [] |
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
service_set_array = node['cookbook']['base_service_set'].to_array | |
tagselector = 'taggedservice:' | |
tagset = (node[:tags].select { |t| t.starts_with?(tagselector) }).collect { |t| t[length(tagseelctor)..-1] } | |
tagset.each do |tagval| | |
service_set_array.append(tagval) | |
end | |
node.normal['cookbook']['service_set'] = service_set_array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got lazy here because I didn't want to keep writing the example out, but the idea is that you could designate 'service1', 'service2', and 'service3' with tags, and then read the contents of
node['cookbook']['service_set']
to power some logic which uses their various 'source_url' attributes