2017-08-28 86 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资源一次控制整个文件内容会更容易和更安全。