【发布时间】:2015-10-01 17:59:52
【问题描述】:
我需要在节点上运行 chef-client 之间保留一些值。从Chef docs 我认为正常的属性用于此
"在 chef-client 运行开始时,所有默认值、覆盖和 自动属性被重置...普通属性永远不会 重置...在厨师客户端运行结束时,全部默认, 覆盖,自动属性消失,只留下一个 将持续到下一个正常属性的集合 厨师客户端运行。”)
但是,如果我使用以下配方引导节点两次
log 'message' do
message "Before setting I am #{node['my_key']}"
level :warn
end
node.normal['my_key'] = 'my value'
log 'message' do
message "After setting I am #{node['my_key']}"
level :warn
end
我希望看到
在设定之前我就是我的价值
在第 2 次运行时(因为该值从第 1 次运行中保持不变)。但是它会再次恢复为未设置。
值是否可能持续存在?我需要以不同的方式运行配方吗?还是根本不可能?
编辑:据我所知,厨师运行成功完成。这是命令和输出:
mfreake@my-linux:/export/apps/chef/chef-repo/cookbooks$ knife bootstrap node1.blah.com --ssh-user mfreake --ssh-password 'yaddayadda' --sudo --use-sudo-password --bootstrap-proxy 'http://proxy.blah.com/' -N node1 --run-list persist_test::read_set_read
Node node1 exists, overwrite it? (Y/N) Y
Client node1 exists, overwrite it? (Y/N) Y
Creating new client for node1
Creating new node for node1
Connecting to node1.marketpipe.com
node1.blah.com [sudo] password for mfreake: -----> Existing Chef installation detected
node1.blah.com Starting first Chef Client run...
node1.blah.com Starting Chef Client, version 12.4.2
node1.blah.com resolving cookbooks for run list: ["persist_test::read_set_read"]
node1.blah.com Synchronizing Cookbooks:
node1.blah.com - persist_test
node1.blah.com Compiling Cookbooks...
node1.blah.com [2015-09-30T17:45:40+01:00] WARN: Cloning resource attributes for log[message] from prior resource (CHEF-3694)
node1.blah.com [2015-09-30T17:45:40+01:00] WARN: Previous log[message]: /var/chef/cache/cookbooks/persist_test/recipes/read_set_read.rb:2:in `from_file'
node1.blah.com [2015-09-30T17:45:40+01:00] WARN: Current log[message]: /var/chef/cache/cookbooks/persist_test/recipes/read_set_read.rb:9:in `from_file'
node1.blah.com Converging 2 resources
node1.blah.com Recipe: persist_test::read_set_read
node1.blah.com * log[message] action write[2015-09-30T17:45:40+01:00] WARN: A message add to the log.
node1.blah.com
node1.blah.com
node1.blah.com * log[message] action write[2015-09-30T17:45:40+01:00] WARN: A message add to the log. my value
node1.blah.com
node1.blah.com
node1.blah.com
node1.blah.com Running handlers:
node1.blah.com Running handlers complete
node1.blah.com Chef Client finished, 2/2 resources updated in 1.621458795 seconds
【问题讨论】:
-
1) 你的厨师运行成功了吗?如果不是什么都保存回服务器。 2) 如果您使用
-o recipe启动chef-client,节点对象也不会保存。你真的摆脱这两种情况了吗? (对于你的最后一个问题,是的,这是可能的并且是有意的) -
谢谢它似乎成功完成。我在上面添加了命令和输出。输出“节点 node1 存在,覆盖它吗?(是/否)” - 问题?如何不覆盖它?
-
确实 bootstrap 应该只使用一次,引导(创建节点对象,创建客户端密钥,安装 chef-client 并首先运行)。当你重做它时,它会覆盖节点对象,所以很明显它在运行时是空的。例如通过knife ssh触发运行,一切都会好的。
-
啊啊啊啊,这解释了很多。多次引导一个节点的想法听起来不正确。我正在使用 Learning Chef 书,也许我只是错过了那一点(尽管我仍然看不到它或在索引中找到它。)。谢谢-如果您想要积分/刻度,请随时将其作为答案
-
如果 book 以 chef11 为目标是正常的,则在 chef12 中的行为发生了轻微的变化,验证器密钥没有复制到节点以便它自己注册,而是提前创建节点。我会尝试在答案中总结一下
标签: chef-infra knife