まず、失敗した努力の要約:
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を実行し、ユーザーの設定がロードされていないので、
が動作しない、doesnの仕事はありません。 1の理由は、いくつかのnilのディレクトリに文句不合理なエラーのuser
属性を指定する必要がありますし、失敗したので yser
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
上記1は動作しません。
レシピgit_sync.rb:
検査時には、私は、今、リソースだけおそらく基礎となるルビーファイルがEtc.getpwnam(..)を使用してLinuxで動作するだろうとソリューションを
を実現しました
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リソース経由でシェフクライアントを実行しています。ドメインユーザーのためのものを設定しました。 – Chiranjib