0

I am trying to set env variable within Chef recipe so that after the recipe is run, I can do echo $VAR1

  bash 'set_env_var' do
    code <<-EOH
      echo export VAR1="https://#{node['fqdn']}" >> /etc/profile
      source /etc/profile
    EOH
    not_if "grep -q VAR1="https://#{node['fqdn']}" >> /etc/profile"
  end

Please let me know if there is a better way to do the same.

meallhour
  • 13,921
  • 21
  • 60
  • 117

1 Answers1

0

This is not a feature that Unix supports. The closest you can get is writing to something like /etc/profile.d if your distro's default shell RC files support it but that both won't have any effect on the current shell (you would need to start a new one) and doesn't cover all execution scenarios. Environment variables are probably the wrong answer to whatever you are trying to solve.

coderanger
  • 52,400
  • 4
  • 52
  • 75