2016-03-30 21 views
0

スクリプトリソースのcwd属性の目的は何ですか?何らかの理由で、私はFile.directoryがあるとは思わないスクリプトリソースのcwd属性のシェフ目的

script 'clone_repo' do 
    interpreter "bash" 
    code <<-EOH 
    cd /var/apps 
    git clone https://gitlab.com/dsura/test-go-web-app.git 
    EOH 
    not_if { ::File.directory?("/var/apps/test-go-web-app") } 
end 

script 'clone_repo' do 
    interpreter "bash" 
    cwd ::File.dirname('/var/apps') 
    code <<-EOH 
    git clone https://gitlab.com/dsura/test-go-web-app.git 
    EOH 
    not_if { ::File.directory?("/var/apps/test-go-web-app") } 
end 

答えて

1

(すなわち/var/apps下のGitのレポをクローニング)最初のブロックの動作を実行しているが、意図したように、第2の1は動作しません。存在するメソッドが、cwd '/var/apps'を意味する場合は違いはありません。これは、サブプロセス(別名、スクリプト)を実行する前に作業ディレクトリを設定します。これはcdのようなものを使用したくないexecuteリソースのほうが重要ですが、scriptexecuteから継承されています。

execute 'git clone https://gitlab.com/dsura/test-go-web-app.git /var/apps/test-go-web-app' do 
    creates '/var/apps/test-go-web-app' 
end 

またはそれ以下のためのGitのリソースを使用します:あなたは、より多くの簡潔その全体のことを書くことができ

git '/var/apps/test-go-web-app' do 
    action :checkout 
    repository 'https://gitlab.com/dsura/test-go-web-app.git' 
end 

それはあなたがaction :checkoutをオフのままに、デフォルト:syncアクションが更新されますシェフが毎回実行するたびにmasterブランチにアクセスしてください。

+0

申し訳ありませんが、 'dirname' – denniss

+0

' dirname( '/ var/apps')== '/ var''と思われます。 – coderanger

関連する問題