I am generating a master token in Chef using the execute resource as below:
execute "extract_consul_key" do
command "consul keygen "
end
I want to store output of this command in a databag.
Please let me know what steps do I need to setup an encrypted databag and then store output of the above execute resource into that databag.
I am new to databags and don't possess any knowledge on it.
execute
, like all Chef resources, doesn't really have "output values". You would want to drop down a level and use the shell_out!
API from inside a Ruby block. I will also state for the record that giving servers write access to data bags is hugely unsafe both from a data integrity PoV (the Chef API has no concept of locking or partial updates) as well as security (though you can reduce this problem with very careful ACL use, but that's a whole different ball of frustration).
If you are new to Chef, and it sounds like you are, don't do this. Run the command once by hand and then add the value to the data bag yourself.