2016-12-12 4 views
1

요리사 조리법 작업에 조건부 보호를 추가하려고합니다. 따라서 특정 환경 변수가 설정된 경우에만 실행됩니다 (CLEAN_DB).요리사 전용 환경 변수를 확인하십시오. 가드 인 경우

execute "create databases" do 
    Chef::Log.info("Cleaning/creating the database") 
    command "psql --file #{node['sql-directory']}/sql/db_create.sql" 
    cwd node['sql-directory'] 
    action :run 
    user node['postgresql-user'] 
    only-if (ENV['CLEAN_DB'] == "create") 
end 

end 앞에 선 권리는 나에게 문제를주고있다. 나는 다음의 모든 노력했습니다

... 
SyntaxError 
----------- 
/home/centos/.jenkins/workspace/test1__Deploy/cache/cookbooks/recipes/app_linux.rb:157: syntax error, unexpected end-of-input, expecting keyword_end 
... 

: 그들 중

only-if ENV['CLEAN_DB'] == "create" 
only-if { ENV['CLEAN_DB'] == "create" } 
only-if '("#{ENV[\'CLEAN_DB\']}" == "create")' 
only-if 'if [[ "$CLEAN_DB" == "create" ]] ; then echo 0 ; else echo 1; fi;' 
only-if 'if [[ "$CLEAN_DB" == "create" ]] ; then echo 0 ; else echo 1; fi' 

그리고 아무도 제대로 작동하지 않습니다 그것은 다음과 같은 구문 오류가 있습니다. 문서 (https://docs.chef.io/resource_common.html)는 0을 출력하는 쉘 스크립트 (쉘 케이스에서는 조건의 문자열 리터럴에 대한 오류를 나타냄) 또는 Ruby 블록 (예제에서는 {} 사이에 있음)을 필요로한다고 제안하는 것 같습니다. 나는이 시점에서 아이디어가 없다.

답변

3

철자가 정확히 only_if이라면 적어도 마지막 블록의 두 번째 시도가 성공해야합니다.

올바른 구문은 다음과 같습니다 또는

execute "create databases" do 
    # Logging here makes IIRC no sense because it's emitted at compile time 
    # Chef::Log.info("Cleaning/creating the database") 
    command "psql --file #{node['sql-directory']}/sql/db_create.sql" 
    cwd node['sql-directory'] 
    action :run 
    user node['postgresql-user'] 
    only_if { ENV['CLEAN_DB'] == "create" } 
end 

, 당신은 너무 많은 감사 Ughhh

only_if do ENV['CLEAN_DB'] == "create" end 
+0

을 사용할 수 있습니다! 내가 실수를 할 때 나는 그것을 싫어 : D 조 –