# Recipe attributes with Inspec

**URL:** <https://discourse.chef.io/t/recipe-attributes-with-inspec/13776>\
**Category:** Chef InSpec\
**Created:** [October 2, 2018, 7:43pm UTC](https://discourse.chef.io/t/recipe-attributes-with-inspec/13776 "2018-10-02T19:43:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmnobarra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/rmnobarra/32/2319_2.png) [@rmnobarra](https://discourse.chef.io/u/rmnobarra)\
**Post date:** [October 2, 2018, 7:43pm UTC](https://discourse.chef.io/t/recipe-attributes-with-inspec/13776/1 "2018-10-02T19:43:27Z")

</div>

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?

Thanks!

---

<div class="post-metadata">

**Author:** ![aleksey\_hariton](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/aleksey_hariton/32/1711_2.png) [@aleksey\_hariton](https://discourse.chef.io/u/aleksey_hariton)\
**Post date:** [October 2, 2018, 10:41pm UTC](https://discourse.chef.io/t/recipe-attributes-with-inspec/13776/2 "2018-10-02T22:41:26Z")

</div>

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:

- [https://github.com/sous-chefs/mysql/tree/master/test/integration](https://github.com/sous-chefs/mysql/tree/master/test/integration)
- usage example for queries - [https://github.com/sous-chefs/mysql/blob/master/test/integration/spec\_helper.rb#L117-L123](https://github.com/sous-chefs/mysql/blob/master/test/integration/spec_helper.rb#L117-L123)
- Password defined in test cookbook - [https://github.com/sous-chefs/mysql/blob/master/test/cookbooks/test/recipes/smoke.rb#L6-L7](https://github.com/sous-chefs/mysql/blob/master/test/cookbooks/test/recipes/smoke.rb#L6-L7)

P.S.

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.

---

<div class="post-metadata">

**Author:** ![minaev](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@minaev](https://discourse.chef.io/u/minaev)\
**Post date:** [May 18, 2021, 10:38am UTC](https://discourse.chef.io/t/recipe-attributes-with-inspec/13776/3 "2021-05-18T10:38:37Z")

</div>

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

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

```

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

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
