1

I'm writing a chef script to install nvm for windows. I've just had a problem where the system ends up with a User and a System variable for NVM_HOME

env 'NVM_HOME' do action :delete end

the above would presumable remove both

How can I amend my chef script to ensure the system variable is kept but the user variable is removed if present?

Paul D'Ambra
  • 7,629
  • 3
  • 51
  • 96
  • I think for this you'll have to make a small script in powershell, see [here](https://technet.microsoft.com/en-us/library/ff730964.aspx) for a starting point. – Tensibai Jan 27 '17 at 12:26
  • yes, was assuming I could shell out and do something like `REG delete HKCU\Environment /F /V FOOBAR` but wondered if it was built in and I was misunderstanding the chef docs – Paul D'Ambra Jan 27 '17 at 12:27
  • I assume playing with the user SSID and `registry_key` resource this is doable, I will need to target KHU//... but that should be doable. – Tensibai Jan 27 '17 at 13:30

2 Answers2

1

If the user environment variable is the user running chef and not another user you can use the registry_key resource to ensure the values are deleted (untested example):

registry_key "HKCU\\Environment" do
  values [{:name => 'NVM_HOME'},{:name => 'NVM_SYMLINK'}]
  action :delete
end

If you wish to change another user variable you can have a look at this answer

Community
  • 1
  • 1
Tensibai
  • 15,557
  • 1
  • 37
  • 57
0

Did this in the end

[ 'NVM_HOME', 'NVM_SYMLINK' ].each do |key| execute "ensure nvm has not added #{key} user variables" do command "REG delete HKCU\\Environment /F /V #{key}" only_if { registry_key_exists? "HKCU\\Environment\\#{key}" } end end

probably not the best way but it ran :)

Paul D'Ambra
  • 7,629
  • 3
  • 51
  • 96