Recipe attributes with Inspec

Hello all,

I wrote some control test for Mysql cookbook and i'd like to run some queries using mysql cli, but, for that, i need to insert root password first. I have this pass stored in a attribute but and don't know how use in my inspec profile. Any idea?


Inspec should be totally independent from your implementation with Chef/Ansible/whatever, even if you know that it will be Chef.

During TEST you have test scenario, which mean you already know some inputs, like password for MySQL.

Actually I already did tests for mysql cookbook, you can check them here:


In worst of the worst of the worst case, you can load inside inspec /tmp/kitchen/nodes/node-name.json with node attrs. But its ugly and contradicts idea of InSpec itself and integration testing specifically.


Sorry for the late reply :slight_smile: When testing existing servers for compliance, I get attribute values using the knife command on the server being tested:

require 'json'
attr_json = JSON.parse(command("knife node show -c /etc/chef/client.rb #{sys_info.hostname('full')} -a '' -Fjson").stdout)

Now, we can access the attribute value using attr_json.values[0][''] or attr_json[sys_info.hostname('full')]['']

As you can see, nodes are named after the server's full hostname, but in case you use a different naming convention, you can get the node name from node_name in /etc/chef/client.rb