# I want to use data bag for store password with community cookbook mysql - how can i do this in elegant way?

**URL:** <https://discourse.chef.io/t/i-want-to-use-data-bag-for-store-password-with-community-cookbook-mysql-how-can-i-do-this-in-elegant-way/4292>\
**Category:** Chef Infra (archive)\
**Created:** [August 7, 2013, 6:18am UTC](https://discourse.chef.io/t/i-want-to-use-data-bag-for-store-password-with-community-cookbook-mysql-how-can-i-do-this-in-elegant-way/4292 "2013-08-07T06:18:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladimir\_Skubriev](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/vladimir_skubriev/32/263_2.png) [@Vladimir\_Skubriev](https://discourse.chef.io/u/Vladimir_Skubriev)\
**Post date:** [August 7, 2013, 6:18am UTC](https://discourse.chef.io/t/i-want-to-use-data-bag-for-store-password-with-community-cookbook-mysql-how-can-i-do-this-in-elegant-way/4292/1 "2013-08-07T06:18:45Z")

</div>

In previous question to the community/maillist I asked about how can i  
store decrypt passwords.  
And a answer is - store it in `node.run_state` hash - this is because  
this is not persistent store and there is only during the launch of chef.

This is very good idea of course. But I can’t understand how can use it  
in real world.

For example I upload mysql community cookbook to my chef server. For  
deploy mysql data base server.

Mysql community cookbook has several default attributes of passwords  
which is randomly generated by openssl. But we can override them.

How can I override them best practice ?

[README.md](http://README.md) at this cookbook has:

node[‘mysql’][‘server\_root\_password’] - Set the server’s root password  
node[‘mysql’][‘server\_repl\_password’] - Set the replication user 'repl’  
password  
node[‘mysql’][‘server\_debian\_password’] - Set the debian-sys-maint user  
password

“OK” said I, How can I setup them with node.run\_state ?

One way is to create application cookbook (  
[http://devopsanywhere.blogspot.ru/2012/11/how-to-write-reusable-chef-cookbooks.html](http://devopsanywhere.blogspot.ru/2012/11/how-to-write-reusable-chef-cookbooks.html))  
and in the recipe mode set vars:

mysql\_acme/recipes/default:  
…

# code to setup node.run\_state[‘mysql’][‘server\_root\_password’] and

others from data bags. i.e. retrive data bags from server, decrypt them etc.  
how can i do this, i has chef error, when set this var: undefined method  
`[]=’ for nil:NilClass ?  
…  
node[‘mysql’][‘server\_root\_password’] =  
node.run\_state[‘mysql’][‘server\_root\_password’]  
…

# before run mysql::server we setup node attributes

include\_recipe “mysql::server”

This is not good idea because I use node attribute that persistent to  
chef server and will be available after chef run to all nodes wia search.  
Despite the fact that I used node.run\_state.

I cannot understand how to use community cookbook with my own data bags?

–  
Best regards,

CVision Lab System Administrator  
Vladmir Skubriev
