问题。以下命令行
knife bootstrap 127.0.0.1 -r 'recipe[chef-client]' -x user -p password --sudo
Run Code Online (Sandbox Code Playgroud)
返回
Bootstrapping Chef on 127.0.0.1
WARNING: Failed to connect to 127.0.0.1 -- Errno::ECONNREFUSED: Connection refused - connect(2)
Run Code Online (Sandbox Code Playgroud)
预计此命令会成功并在它之后
knife node list
Run Code Online (Sandbox Code Playgroud)
将返回
[
"127.0.0.1"
]
Run Code Online (Sandbox Code Playgroud)
SSH 服务器在 localhost 上工作正常,ssh user@127.0.0.1 -p password并按预期工作。
我有一个厨师食谱,我想获取 node['cfn']['environment'] 下的所有属性并将它们写入 yml 文件。我可以做这样的事情(它工作正常):
content = {
"environment_class" => node['cfn']['environment']['environment_class'],
"node_id" => node['cfn']['environment']['node_id'],
"reporting_prefix" => node['cfn']['environment']['reporting_prefix'],
"cfn_signal_url" => node['cfn']['environment']['signal_url']
}
yml_string = YAML::dump(content)
file "/etc/configuration/environment/platform.yml" do
mode 0644
action :create
content "#{yml_string}"
end
Run Code Online (Sandbox Code Playgroud)
但我不喜欢我必须明确列出属性的名称。如果稍后我添加一个新属性,如果它自动包含在写出的 yml 文件中,那就太好了。所以我尝试了这样的事情:
yml_string = node['cfn']['environment'].to_yaml
Run Code Online (Sandbox Code Playgroud)
但是因为节点实际上是一个 Mash,所以我得到了一个像这样的 platform.yml 文件(它包含很多我不想要的意外嵌套):
--- !ruby/object:Chef::Node::Attribute
normal:
tags: []
cfn:
environment: &25793640
reporting_prefix: Platform2
signal_url: https://cloudformation-waitcondition-us-east-1.s3.amazonaws.com/...
environment_class: Dev
node_id: i-908adf9
...
Run Code Online (Sandbox Code Playgroud)
但我想要的是这个:
----
reporting_prefix: Platform2
signal_url: https://cloudformation-waitcondition-us-east-1.s3.amazonaws.com/...
environment_class: Dev
node_id: i-908adf9
Run Code Online (Sandbox Code Playgroud)
如何在不按名称显式列出属性的情况下实现所需的 yml 输出?
Chef-solo 缺乏环境支持似乎很有争议。一方面,环境的特征之一是能够将食谱固定到特定环境,而这对于 Chef-solo 来说完全没有意义。另一方面,我们很多人都希望在使用 Vagrant 进行测试时能够合并环境级别的属性并使用特定于环境的运行列表。我想我可能已经找到了一个简单的方法来解决这个问题。假设我在所有环境和角色中使用 JSON 语法,并且我坚持以下约定来设置属性(从最低到最高优先级):
看起来我可以自己解析这些文件并使用 -j 选项将属性注入到chef-solo中。例如,我可以在我的 Vagrantfile 中做这样的事情:
chef_env_conf = parse_json("./environments/#{ENV['CHEF_ENVIRONMENT']}.json")
chef.json = chef_env_conf["override_attributes"]
Run Code Online (Sandbox Code Playgroud)
由于通过 -j 选项设置的属性在正常优先级级别应用,因此这可以是覆盖角色默认值的另一种方法,并且这可能是您在未自动拉入环境的上下文中所需的全部内容。
您可以执行类似的操作来获取每个环境的运行列表(通过解析角色文件):
chef_role_conf = parse_json("./roles/#{role}.json")
chef.run_list = chef_role_conf["env_run_lists"][ENV['CHEF_ENVIRONMENT']]
Run Code Online (Sandbox Code Playgroud)
我意识到这不是最优雅的 hack,但对于某些人来说,这似乎是一个可行的解决方案。有没有人认为这是一个非常糟糕的主意?
我想chef-client在运行时传递一些属性。有没有办法做同样的事情?我正在研究chef-client -j选项,但据我所知,它可用于指定 run_list。我可以在其中传递一些属性吗?如果是,如何?
温柔一点,我是厨师的新手,正在尝试设置我的环境并将一些新食谱上传到我的新厨师服务器。我能够执行一些命令,并且能够访问knife bootstrap新节点,因此我很确定我的配置是正确的。
当我打开详细日志记录时,它似乎正在尝试上传到本地主机。我在我的 中设置了一个服务器knife.rb,我还尝试在 Knife 命令中使用 指定一个服务器-s,但无济于事。
$ knife cookbook upload -a
Uploading base [0.1.0]
Uploading dovecot [0.1.0]
Uploading postfix [0.1.0]
/opt/chef/embedded/lib/ruby/1.9.1/net/http.rb:762:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
Run Code Online (Sandbox Code Playgroud)
使用指定服务器:
$ knife cookbook upload -a -s https://mychefserver
Uploading base [0.1.0]
Uploading dovecot [0.1.0]
Uploading postfix [0.1.0]
/opt/chef/embedded/lib/ruby/1.9.1/net/http.rb:762:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
Run Code Online (Sandbox Code Playgroud)
并使用 -V:
$ knife cookbook upload -a -s https://mychefserver -V
Uploading base [0.1.0]
Uploading dovecot [0.1.0]
Uploading postfix [0.1.0]
INFO: Validating ruby …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个厨师食谱,以使我的网站运行,并且一切似乎都运行良好,但uWSGI出现以下错误:
*** has_emperor mode detected (fd: 6) ***
[uWSGI] getting INI configuration from app-cms.ini
removed uwsgi instance app-cms.ini
Run Code Online (Sandbox Code Playgroud)
不再说这个:
open("/var/www/app-cms/logs/uwsgi.log"): Permission denied [utils.c line 246]
Run Code Online (Sandbox Code Playgroud)
现在正在创建该日志文件,其中包含以下内容:
*** Starting uWSGI 1.0.3-debian (64bit) on [Thu Feb 6 12:00:43 2014] ***
compiled with version: 4.6.3 on 17 July 2012 02:26:54
current working directory: /etc/uwsgi/apps-enabled
writing pidfile to /var/www/ediflo-cms/run/ediflo-cms.pid
detected binary path: /usr/bin/uwsgi-core
setgid() to 33
setuid() to 33
chdir(): Permission denied [uwsgi.c line 1723]
chdir(): Permission denied [uwsgi.c line 975]
Run Code Online (Sandbox Code Playgroud)
我不确定它试图去哪里 …
Chef 拥有官方 AWS 说明书 ( https://github.com/opscode-cookbooks/aws ),它允许启动 AWS 资源以及更新资源标签。
可以在配方中使用 AWS 说明书引入的自定义资源来读取 AWS 资源标签吗?帮助文档中列出的唯一资源用于更新/创建/删除这些标签。
我的目标是能够根据特定的 AWS 标签确定 Chef 环境。
我有一个自托管的 Chef 服务器。我可以knife upload访问该服务器,并以其他方式与之交互。因此,我的knife.rb工作正常。我最近对一本食谱进行了参数化,以使其成为一系列相关食谱的基础。
问题是我希望这本食谱是私有的,所以它只存在于我的私人 Chef 服务器上。不幸的是,我不能berks install在我的其他食谱上做。我指着我Berksfile的厨师服务器:
source https://chef.myhost.com
这不起作用。我认为这是因为该 URL 用于 Chef Manage,而不是 Chef Server API。但是,我不知道如何让 Berkshelf 识别我的 Chef Server 并使用其 API。
完整的错误:
> berks install
Resolving cookbook dependencies...
Fetching 'blog_role' from source at .
Fetching cookbook index from chef.myhost.com...
Error retrieving universe from source: chef.myhost.com * [Berkshelf::APIClient::BadResponse] bad response #<Faraday::Response:0x36ae618 @on_complete_callbacks=[], @env=#<Faraday::Env @method=:get @body="<html><body>You are being <a href=\"chef.myhost.com:443/signup\">redirected</a>.</body></html>" @url=#<URI::HTTPS:0x36891f0 URL:chef.myhost.com/universe> @request=#<Faraday::RequestOptions timeout=30, open_timeout=30> @request_headers={"User-Agent"=>"Faraday v0.9.1"} @ssl=#<Faraday::SSLOptions (empty)> …Run Code Online (Sandbox Code Playgroud) 我想检查是否有奴隶数据包。如果有一个,并且它包含数据,那么我想为每个从站执行一个操作。
我有以下代码:
slaves = data_bag('slaves')
if slaves.length > 0
for slave in slaves
...xyz..
end
end
Run Code Online (Sandbox Code Playgroud)
这有效,除非数据包尚不存在。如何检查数据包是否存在?还是我这样做完全错误?
查看此官方文档:https : //docs.chef.io/resource_template.html我看到了将变量传递给使用“{”、“({”或“(”) 来限定变量范围的模板资源的示例。
我找不到解释差异的地方或为什么我会使用一种形式而不是另一种形式。运行配方时真的有什么实际区别吗?
template '/tmp/config.conf' do
source 'config.conf.erb'
variables(
:config_var => node['configs']['config_var']
)
end
Run Code Online (Sandbox Code Playgroud)
template '/tmp/config.conf' do
source 'config.conf.erb'
variables{
:config_var => node['configs']['config_var']
}
end
Run Code Online (Sandbox Code Playgroud)
template '/tmp/config.conf' do
source 'config.conf.erb'
variables({
:config_var => node['configs']['config_var']
})
end
Run Code Online (Sandbox Code Playgroud)