代码之家  ›  专栏  ›  技术社区  ›  Cesare

在Chef中配置Apache(http.conf)

  •  0
  • Cesare  · 技术社区  · 9 年前

    我对使用Chef很陌生:我需要在CentOS 7上配置我的Apache post_inst_config.rb 我以这种方式把它放在我的厨师名单上。。。

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

    post\u inst\u配置。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\u inst\u配置。rb型 Apache已安装并运行良好。

    感谢您的建议。。。

    1 回复  |  直到 9 年前
        1
  •  1
  •   coderanger    9 年前

    这是一个两通问题,看到了吗 https://coderanger.net/two-pass/ 具体来说,但基本上事情并不是按照你认为的顺序发生的。要么把代码移到 ruby_block 资源(不过请注意,您没有检查该行是否已经存在,因此它将在每次运行时重新添加它)或类似于 poise-file 食谱或 line 有用于修改文件的资源的cookbook。我们确实不建议使用这种方式就地修改文件,使用 template

    推荐文章