title: difference between node.run_state vs global varibale in a ruby file chef
body: <p>would like to know the difference and recommended approach to use between global variable vs node.run_state</p>
  
  <p><strong>test.rb</strong></p>
  
  <pre><code>dbpassword=''
  
  
  ruby_block "load_databag_secret" do
    block do
      secret_key = Chef::EncryptedDataBagItem.load_secret("/home/test/db_key")
          db_keys = Chef::EncryptedDataBagItem.load("mydatabag", "mydatabagitem", secret_key) 
      end
      dbpassword=db_keys['DB_PASSWORD']
  node.run_state['password']=db_keys['DB_PASSWORD']
        end
      end
  
  execute "Enable on hosts" do
  
    command lazy { "echo #{node.run_state['password']} &gt; /home/app/db.txt" }
  end
  
      template "/config/properties" do
              source "properties.erb"
              variables(lazy {
                           :db_password =&gt; { node.run_state['password'] },
  
                        })
  </code></pre>
  
  <p>or using node.run_state['password'] in place of global variable in this .rb file</p>
  
  <p>Now execute command worked fine im able to see the password on the echoed file db.txt where as when i used lazy in template variables it outputed as empty value for db_password in template.</p>