# Databag password issues

**URL:** <https://discourse.chef.io/t/databag-password-issues/14615>\
**Category:** Chef Automate\
**Created:** [February 27, 2019, 6:12pm UTC](https://discourse.chef.io/t/databag-password-issues/14615 "2019-02-27T18:12:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandeepiii](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@sandeepiii](https://discourse.chef.io/u/sandeepiii)\
**Post date:** [February 27, 2019, 6:12pm UTC](https://discourse.chef.io/t/databag-password-issues/14615/1 "2019-02-27T18:12:44Z")

</div>

Hi Experts:

Iam writing in the provide to create a method which can be used in the recipe ,(which i have shown in below)  
But this gives me error pw NoMethodError: undefined method `pw'  
provides :cms\_mysql\_password, platform\_family: 'rhel'  
action :create do

pw = ''  
data\_bag('secrets').each do |item|  
db = data\_bag\_item('secrets', item)  
db['users'].each\_pair do |\_k, v|  
pw = v['password'] if v['id'] == 'root'  
end  
end  
end  
action :create do  
script 'set database password' do  
interpreter 'bash'  
user 'root'  
cwd '/tmp'  
code \<\<-EOH  
root\_temp\_pass=$(grep 'A temporary password' /mysql/log/mysqld.log |tail -1 |awk '{split($0,a,": "); print a[2]}')  
mysql -uroot -p"$root\_temp\_pass" --connect-expired-password -Be "ALTER USER 'root'@'localhost' IDENTIFIED BY '#{pw}';"  
EOH  
end  
Below is my recipe which is working fine.  
pw = ''  
data\_bag('secrets').each do |item|  
db = data\_bag\_item('secrets', item)  
db['users'].each\_pair do |\_k, v|  
pw = v['password'] if v['id'] == 'root'  
end  
end  
cms\_mysql\_password 'create-password' do  
action :create

not\_if "mysql -u root -p'#{pw}'"  
end

---

<div class="post-metadata">

**Author:** ![MattRay](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/mattray/32/47_2.png) [@MattRay](https://discourse.chef.io/u/MattRay)\
**Post date:** [February 27, 2019, 8:13pm UTC](https://discourse.chef.io/t/databag-password-issues/14615/2 "2019-02-27T20:13:03Z")

</div>

In your suite, just add additional entries like this:

```
run_list:
  - recipe[chef-client::config]
  - recipe[audit::default]
```

---

<div class="post-metadata">

**Author:** ![r2oro](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@r2oro](https://discourse.chef.io/u/r2oro)\
**Post date:** [February 28, 2019, 3:39pm UTC](https://discourse.chef.io/t/databag-password-issues/14615/3 "2019-02-28T15:39:49Z")

</div>

So you already have it so...

However your wording (run first mysql::default finishes/completes,then the second recipe mysql::data should start ) is somehow questionable.

All cookbooks/recipes are loaded at once at the beginning of chef-client run.

Then their attributes are processed (executed) in run\_list order, then recipes are all 'compiled' (Ruby code in recipes is executed) producing list of resources to be converged. Then, at last that list is converged.

So processing of first cookbook/recipe will never be complete before the rest of them is 'started'.

Regards,  
Artur
