Skip to content

Instantly share code, notes, and snippets.

@sirosen
Created September 22, 2015 15:34
Show Gist options
  • Save sirosen/e1a7a831d26bf461c438 to your computer and use it in GitHub Desktop.
Save sirosen/e1a7a831d26bf461c438 to your computer and use it in GitHub Desktop.
ChefAttributesByTagsDemo
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'] = []
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
@sirosen
Copy link
Author

sirosen commented Sep 22, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment