简体   繁体   中英

Opscode CHEF(11.12.8) - chef-client can't add env. var. to PATH

I'm using chef-client(11.12.8) with windows nodes(Win Server 2012).

I install perforce client. To do so I launch in a CMD chef-client in order to execute my cookbook.

Perforce installation set in PATH the appropriate path to p4.exe. But in the cmd where I launch chef-client command the PATH is not updated. So after, in my cookbook when I try to execute the command 'p4 sync' in a windows_batch resource it fails.

Solutions I try,

1/
set PATH=%PATH%;C:\\Program Files\\Perforce
in a windows_batch resource before launching a p4 sync command.
DID NOT WORK.

2/
Put the previous command in a batch.
DID NOT WORK.

3/
$env:Path = $env:Path + ";C:\\Program Files\\Perforce"
in a powershell_script resource before launching a p4 sync command.
DID NOT WORK.

Is there a way to do that ?
Instead of using:
C:\\Program Files\\Perforce\\p4.exe

THANKS


UPDATE_01

the code but i don't think it would help so much...

Install perforceClient

windows_package 'Perforce Client' do
  source 'PerforceClient_2014.1\\p4vinst64.exe'
  options '/s /v"/qn"'
  installer_type :custom
  action :install
end

...

windows_batch 'Perforce sync' do
  code <<-EOH
  p4 sync //APP/
  EOH
end

Here the p4 command is unknow from the cmd where I launch chef-client command. I will have a look at the batch resource. Thanks

windows_package 'Perforce Client' do
  source 'PerforceClient_2014.1\\p4vinst64.exe'
  options '/s /v"/qn"'
  installer_type :custom
  action :install
  notifies :run, "execute[PerforceSync]", :immediately
end

execute 'PerforceSync' do
 action :nothing
 command 'p4 sync //APP/'
 environment { "PATH": "#{ENV['PATH']};C:\Program Files\Perforce" }
end

No need to use a windows_batch resource to execute a single command.

I use action nothing in the execute resource to avoid executing it at each run and only notify it to run when the package is installed.

windows_batch or batch resource exist to transpose existing batches. I'm sure you don't write a .bat or .cmd file to run a single command.

execute resource documentation is HERE

Side note: you should consider adding a guard to any execute or batch resource if it is not driven by another resource, see This as a starting point.

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