첫째, 실패 노력의 요약 :
powershell_script 'git-sync' do
cwd "#{ENV['HOME']}']}"
code <<-EOH
git pull
EOH
end
자원이
ruby_block 'git-sync' do
block do
script <<-EOH
git pull
EOH
end
result = powershell_out(script)
if (!result.stdout.to_s.empty?)
Chef::Log.info("GIT command output::\n#{result.stdout.to_s}")
end
end
같은 문제를 -noprofile 태그로 PowerShell을 실행하고 사용자의 설정이로드되지 않기 때문에
가 작동하지 않습니다, 아무튼 일하지 마라. 이제 르 강
git "#{node.run_state['git_directory']}" do
repository "#{node.run_state['git_repo']}"
revision "#{node.run_state['git_branch']}"
action :sync
user "#{ENV['USER']}"
end
하나 user
속성을 지정하는 때문에 일부 nil이 디렉토리에 대해 불평 터무니없는 오류로 실패하기 때문에 하나 이상 작동하지 않습니다.
조리법 git_sync.rb :
검사시, 나는 자원은 아마
이제 리눅스 기본 루비 파일이 Etc.getpwnam을 사용합니다 (..)와 함께 솔루션을 작동 할 것을 깨달았다
ruby_block 'git-sync' do
block do
psFile = "#{Chef::Config[:file_cache_path]}/cookbooks/#{cookbook_name}/files/git_align.ps1"
node.run_state['git_directories'].each { |location|
scriptOutput = `powershell.exe -NoLogo -NonInteractive -File #{psFile} #{location} #{node.run_state['git_branch']}`
Chef::Log.info("Git Sync Output::\n#{scriptOutput}")
}
end
end
PowerShell 스크립트 git_align.ps1 :
Param(
[string]$location,
[string]$branch_name
)
Try{
$output = ""
$loc = Resolve-Path -path $location
if ($loc -eq $null) {throw "$location not found"}
Set-Location $loc
$output+= "At location $loc`n"
$curr_branch = git rev-parse --abbrev-ref HEAD
if ($curr_branch -ne $branch_name){
$output+= git checkout $branch_name
$output+= "`n"
}
if ($? -eq $false) {throw "GIT checkout failed"}
$output+= git reset --hard origin/$branch_name
$output+= "`n"
if ($? -eq $false) {throw "GIT reset failed"}
$output+= git pull
$output+= "`n"
if ($? -eq $false) {throw "GIT pull failed"}
Write-Output $output
}
Catch{
$exc = $_.Exception | format-list -force
Write-Output $exc
Throw $exc
}
희망 하시겠습니까? 주방장은 때로는 바다처럼 보이며 아무도 혼자 수영을해서는 안됩니다!
요리사 레시피를 실행하는 사용자는 누구입니까? 다른 사용자이거나 다른 사용자로 시작한 서비스를 통해 실행중인 경우 해당 사용자에 대해 aws와 git를 모두 구성해야합니다. – arco444
windows_task 리소스를 통해 내 chef-client를 실행하여 도메인 사용자가 내가 물건을 구성했습니다. – Chiranjib