Last active
August 29, 2015 14:22
-
-
Save dairennlombard/9820a82f45c734160983 to your computer and use it in GitHub Desktop.
Ruby vars as an array element name?
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
# data_bag JSON: | |
{ | |
"id": "example_data_bag_id", | |
"example_account": { | |
"private_value": "Example Private Data", | |
"public_value": "Example Public Data" | |
} | |
} | |
# Recipe: | |
# node['example_cookbook']['databagname'] = 'example_account' | |
databagid = node['example_cookbook']['databagname'] | |
# At this point, #{databagid} should = "example_account" | |
chefkey = Chef::EncryptedDataBagItem.load_secret(node['example_cookbook']['secretpath']) | |
databagarray = Chef::EncryptedDataBagItem.load(databagid, 'example_data_bag_id', chefkey) | |
# Should be like passing ('example_account', 'example_data_bag_id', chefkey) | |
privatevalue = databagarray["#{databagid}"]['private_value'] | |
publicvalue = databagarray["#{databagid}"]['public_value'] | |
# Is it possible to use a Ruby var as an array element name in this way? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
data_bag JSON:
Databag name: example_data_bag
{
"id": "example_data_bag_item",
"example_account": {
"private_value": "Example Private Data",
"public_value": "Example Public Data"
}
}
Recipe:
chefkey = Chef::EncryptedDataBagItem.load_secret(node['example_cookbook']['secretpath'])
databagarray = Chef::EncryptedDataBagItem.load('example_data_bag', 'example_data_bag_item', chefkey)
privatevalue = databagarray["example_account"]['private_value']
publicvalue = databagarray["example_account"]['public_value']