Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Chef infra 为什么不';难道我的厨师没有保持正常的属性吗?_Chef Infra_Knife - Fatal编程技术网

Chef infra 为什么不';难道我的厨师没有保持正常的属性吗?

Chef infra 为什么不';难道我的厨师没有保持正常的属性吗?,chef-infra,knife,Chef Infra,Knife,我需要在节点上的chef客户端运行之间保留一些值。从这个角度看,我认为这是正常的属性 “在chef客户端运行开始时,所有默认、重写和 自动属性被重置…普通属性永远不会被重置 重置…在chef客户端运行结束时,所有默认值, 覆盖,自动属性消失,只留下一个 将持续到下一个 厨师长(客户运行) 但是,如果我使用以下方法引导节点两次 log 'message' do message "Before setting I am #{node['my_key']}" level :warn end

我需要在节点上的chef客户端运行之间保留一些值。从这个角度看,我认为这是正常的属性

“在chef客户端运行开始时,所有默认、重写和 自动属性被重置…普通属性永远不会被重置 重置…在chef客户端运行结束时,所有默认值, 覆盖,自动属性消失,只留下一个 将持续到下一个 厨师长(客户运行)

但是,如果我使用以下方法引导节点两次

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
我希望他们能看到

在设定我的价值之前

在第二次运行时(因为该值是从第一次运行时保留的)。然而,它又恢复为未设置

该值是否可能持续存在?我需要以不同的方式运行配方吗?还是不可能

编辑:据我所知,Chef运行已成功完成。以下是命令和输出:

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

您应该尝试
node.set['my_key']='my value'
(或者使用
node.set_,除非
,以确保在有人更改chef服务器上的属性时可以安全地保留)

好,有两种情况下,节点状态(包括属性)无法保存回chef服务器:

  • 当运行以错误结束时(此处取决于错误,状态仍可以保存,但它超出了此问题的范围)
  • 运行
    chef client-o any_recipe_list
    此处的
    -o
    选项用于临时覆盖运行列表,因此它不会保存回chef服务器以不覆盖实际运行列表
  • node.normal
    node.set
    是同一件事,将值写入要存储在服务器上的节点对象中

    这里的问题是由于使用了
    knife bootstrap
    (版本>12.1,根据),它首先在chef服务器上创建节点及其客户端密钥。调用它两次并允许它覆盖上一个对象重置整个节点对象


    bootstrap
    应该只使用一次,以后运行的任何chef客户端都应该通过另一种方式触发(crontab、knife ssh等)。

    设置为
    normal
    的别名,这不会解决OP问题。@Tensbai您有链接吗?实际上,我昨晚搜索了代码库,没有找到它的
    def
    。因此,我的帖子不是说“我知道答案是X”,而是说“你应该试试……”(见上面属性文档的链接,从代码库看,这是别名行,上面的别名是普通方法
    node['key']=value
    也可以用于同一个目标,并委托给定义的
    Chef::node::Attribute
    类。我个人坚持使用
    节点['key']
    表单读取属性,并使用
    节点。方法['key']
    设置属性(其中方法可以是任何属性优先级),感谢指针。我搜索了
    def set
    ,但没有想到要查找别名!:)1) 你的厨师成功结束了吗?如果没有,则不会将任何内容保存回服务器。2) 如果使用
    -o recipe
    启动chef客户端,则也不会保存节点对象。你真的摆脱了这两个案子吗?(对于你的最后一个问题,是的,这是可能的,也是有意的)谢谢,它似乎成功地完成了。我在上面添加了命令和输出。是否输出“Node node1存在,覆盖它?(Y/N)”-问题出在哪里?我怎样才能不覆盖它呢?实际上,引导应该只使用一次,以引导(创建节点对象、创建客户机密钥、安装chef client并执行首次运行)。在重做时,它会覆盖节点对象,因此在运行时它显然是空的。例如,通过ssh触发运行,一切都会好起来。啊,这解释了很多。多次引导节点的想法听起来并不正确。我正在使用《学习厨师》这本书,也许我错过了这一点(尽管我仍然看不到它或在索引中找不到它)。谢谢-如果您想要点/滴答声,请随意回答。如果书籍目标chef11是正常的,则在chef12中的行为发生了轻微的变化,验证程序密钥不会复制到节点以供其注册,而是提前创建节点。我将尝试在回答中对此进行总结