Chef 工具:安装 httpd 时提示需要提及版本

Chef 工具:安装 httpd 时提示需要提及版本

我写的代码

[root@ns1 sysadmin]# cat installstarthttpd.rb 
package' httpd'

service 'httpd' do
       action [:start, :enable]
end

file '/var/www/html/index.html' do
       content '        <html>
                       <title>
                       Page from Chef
                       </title>
                       <body>
                       <h1> Welcome Raja</h1>
                       </body>
                       </html>
               '
end

[root@ns1 sysadmin]# 

我执行了下面的命令,得到了如下错误

[root@ns1 sysadmin]# chef-apply installstarthttpd.rb
Recipe: (chef-apply cookbook)::(chef-apply recipe)
 * package[ httpd] action install
   * No version specified, and no candidate version available for  httpd
   ================================================================================
   Error executing action `install` on resource 'package[ httpd]'
   ================================================================================

   Chef::Exceptions::Package
   -------------------------
   No version specified, and no candidate version available for  httpd

   Resource Declaration:
   ---------------------
   # In installstarthttpd.rb

     1: package' httpd'
     2: 

   Compiled Resource:
   ------------------
   # Declared in installstarthttpd.rb:1:in `run_chef_recipe'

   package(" httpd") do
     action :install
     retries 0
     retry_delay 2
     guard_interpreter :default
     package_name " httpd"
     timeout 900
     cookbook_name "(chef-apply cookbook)"
     recipe_name "(chef-apply recipe)"
   end

[2014-10-14T01:10:18-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-10-14T01:10:18-04:00] FATAL: Chef::Exceptions::Package: package[ httpd] ((chef-apply cookbook)::(chef-apply recipe) line 1) had an error: Chef::Exceptions::Package: No version specified, and no candidate version available for  httpd

我也看到了日志

[root@ns1 sysadmin]# cat /var/chef/cache/chef-stacktrace.out 
Generated at 2014-10-14 01:10:18 -0400
Chef::Exceptions::Package: package[ httpd] ((chef-apply cookbook)::(chef-apply recipe) line 1) had an error: Chef::Exceptions::Package: No version specified, and no candidate version available for  httpd
/opt/chefdk/embedded/apps/chef/lib/chef/mixin/why_run.rb:241:in `run'
/opt/chefdk/embedded/apps/chef/lib/chef/mixin/why_run.rb:322:in `block in run'
/opt/chefdk/embedded/apps/chef/lib/chef/mixin/why_run.rb:321:in `each'
/opt/chefdk/embedded/apps/chef/lib/chef/mixin/why_run.rb:321:in `run'
/opt/chefdk/embedded/apps/chef/lib/chef/provider.rb:135:in `process_resource_requirements'
/opt/chefdk/embedded/apps/chef/lib/chef/provider.rb:111:in `run_action'
/opt/chefdk/embedded/apps/chef/lib/chef/resource.rb:648:in `run_action'
/opt/chefdk/embedded/apps/chef/lib/chef/runner.rb:49:in `run_action'
/opt/chefdk/embedded/apps/chef/lib/chef/runner.rb:81:in `block (2 levels) in converge'
/opt/chefdk/embedded/apps/chef/lib/chef/runner.rb:81:in `each'
/opt/chefdk/embedded/apps/chef/lib/chef/runner.rb:81:in `block in converge'
/opt/chefdk/embedded/apps/chef/lib/chef/resource_collection.rb:98:in `block in execute_each_resource'
/opt/chefdk/embedded/apps/chef/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
/opt/chefdk/embedded/apps/chef/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
/opt/chefdk/embedded/apps/chef/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/opt/chefdk/embedded/apps/chef/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
/opt/chefdk/embedded/apps/chef/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/opt/chefdk/embedded/apps/chef/lib/chef/resource_collection.rb:96:in `execute_each_resource'
/opt/chefdk/embedded/apps/chef/lib/chef/runner.rb:80:in `converge'
/opt/chefdk/embedded/apps/chef/lib/chef/application/apply.rb:144:in `run_chef_recipe'
/opt/chefdk/embedded/apps/chef/lib/chef/application/apply.rb:153:in `run_application'
/opt/chefdk/embedded/apps/chef/lib/chef/application/apply.rb:166:in `run'
/opt/chefdk/embedded/apps/chef/bin/chef-apply:25:in `<top (required)>'
/usr/bin/chef-apply:34:in `load'

请帮帮我,我遗漏了什么吗?

谢谢。

答案1

您遇到的最可能的问题是您的 yum 数据库尚未更新。您有两个选择:

  1. 使用以下命令在您的机器上手动更新 yum 数据库:

    sudo yum update –y
    
  2. 创建一个 chef 配方(或另一个 chef 配方中的一行),在运行其余命令之前更新 yum 数据库。您可以使用以下行执行此操作:

    execute 'yum update -y'
    

答案2

我也遇到过同样的问题。RedHat 无法httpd从存储库下载。您需要为 RedHat 配置 CentOs-Base 存储库。

  1. 创建文件centos-base.repo包含以下内容/etc/yum.repos.d(更改此文件的发布版本,以下快照适用于发布版本 6)

yum.repos.d

#####################################################################
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-6 - Base
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/6/os/$basearch/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-6 - Updates
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/6/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-6 - Extras
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/6/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6 - Plus
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/6/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-6 - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/6/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


#####################################################################
  1. 从 centos 官方网站下载适用于您的操作系统版本的 gpg 密钥http://mirror.centos.org/centos/并将其移至/etc/pki/rpm-gpg/

    2.1 $cd /etc/pki/rpm-gpg/

    2.2 $wget http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

重要的

还要检查您的互联网连接。根据我的经验,有时 Linux 无法使用默认设置“看到”网络。

主要资源

原始来源这里

答案3

在写包名称时,删除 h 前面的空格。它应该是 'httpd' 而不是 ' httpd'

相关内容