0

New to Chef, bare wi/ me. Building my cookbook.

RayMontez
  • 9
  • 5

2 Answers2

0

How did you set the databag?

are you able to get the credential out using :

$ knife vault show nameOfVault nameOfItem

or

$ knife data bag show nameOfVault nameOfItem_keys
ywainberg
  • 15
  • 4
  • I didn't use knife to create the databag, but rather just create a new 'data_bags' directory & created the JSON file inside the directory since I'm using Vagrant to run it. Is that wrong what I did? Or can I still use knife to see if I can get the credentials? – RayMontez Mar 07 '18 at 16:09
  • chef need to recognize the databag ,can you see the databag in chef manage? – ywainberg Mar 11 '18 at 10:41
  • I'm not using the Chef Manager as I'm only running it on a Vagrant VM. – RayMontez Mar 12 '18 at 15:02
0

Glad you have your data bag loading and indeed, with Test Kitchen you do not need to use knife to upload to Chef Server, as Test Kitchen uses Chef Zero / Solo.

The issue you have here is that you have not correctly formatted reading from the data bag object once you have read. You need to do this instead:

ruby_block "insert_line" do
  block do
    file = Chef::Util::FileEdit.new('/var/lib/net-snmp/snmpd.conf')
    file.insert_line_if_no_match("/www.example.com/", "createUser 
       #{snmp3usercreds['user']} 
       SHA #{snmp3usercreds['auth_pssword']} 
       AES #{snmp3usercreds['enc_password']} ")
    file.write_file
  end
end

So, you will see I have changed snmp3usercreds[user] to snmp3usercreds['user'] with quotes around the user to show it is a string (rather than a variable as is the case with your code).

Belogix
  • 8,129
  • 1
  • 27
  • 32
  • Thank you. Can't believe I missed that. However, I think I may have spoken too soon on the data bag correctly loading. When I use snmp3usercreds = data_bag('snmp3_user_creds'), it loads, but I don't think this is correct as I should be using: snmp3usercreds = data_bag('snmp3_user_creds', 'credentials'). When I do that, it's still not loading. Any ideas? – RayMontez Mar 07 '18 at 22:06
  • I meant to say I should be using data_bag_item('snmp3_user_creds', 'credentials'). – RayMontez Mar 07 '18 at 22:26