2017-08-28 116 views
0

我在使用Chef時非常新鮮:我需要在CentOS 7 上配置我的Apache,所以我創建了一個名爲post_inst_config.rb的小配方,我把它放在我的Chef runlist中這樣...廚師配置Apache(http.conf)

"recipe[mapserver_install::inst_apache2]", 
"recipe[mapserver_install::post_inst_config]" 

在這裏,你是我的post_inst_config.rb

#Add to /etc/httpd/conf/httpd.conf the string: ScriptAlias /cgi-bin/ /var/www/cgi-bin/ 
File.open("/etc/httpd/conf/httpd.conf", 'a') do |file| 
    file.write "ScriptAlias /cgi-bin/ /var/www/cgi-bin/" 
    file.write "\n" 
end 

#Define the following symblink: ln -s /usr/bin/mapserv /var/www/cgi-bin/mapserv 
link '/usr/bin/mapserv' do 
    to '/var/www/cgi-bin/mapserv' 
end 

#Create the directory for the imagepath ... 
directory '/var/www/html/output' do 
    owner 'root' 
    group 'root' 
    mode '0755' 
    action :create 
end 

#Restart apache .... 
service "httpd" do 
    action :restart 
end 

當我嘗試執行我的廚師食譜我得到這個錯誤...

================================================================================ 
    Recipe Compile Error in /var/chef/cache/cookbooks/mapserver_install/recipes/post_inst_config.rb 
    ================================================================================ 

    Errno::ENOENT 
    ------------- 
    No such file or directory @ rb_sysopen - /etc/httpd/conf/httpd.conf 

請注意,如果我嘗試執行我的運行列表而沒有安裝post_inst_config.rb Apache,並且工作正常。

建議表示讚賞...

回答

1

這是一個雙通道的問題,請參見https://coderanger.net/two-pass/的細節,但基本的東西都沒有,你認爲他們是爲了發生。將代碼移動到ruby_block資源(儘管請注意,您並未檢查該行是否已經存在,因此每次運行都會重新添加它),或者我們可以使用類似poise-file cookbook或line cookbook的資源來修改文件。我們不推薦這種修改文件的風格,使用template資源一次控制整個文件內容會更容易和更安全。