简体   繁体   中英

How can you use a Chef recipe to set an environment variable by reading from Shell script?

I need to read the credentials from Shell script and set it as environmental variable.

Previous code in chef

ENV['password'] = '123'

Now I'm trying to use below code but it is not working.

bash 'set_password' do
  code <<-EOH
          password=$(sh /opt/get_password.sh root)
      EOH
  guard_interpreter :bash
  environment ({ 'password' => $password })
end unless node.attribute?('ec2')

If you want the output (stdout) of the get_password.sh script into an environment variable, you can simply do:

ENV['password'] = `/opt/get_password.sh root`

Then this environment variable can be referenced in other places of the recipe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM