加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 关于attributes-字符串不匹配的Chef错误

发布时间:2020-12-17 01:34:26 所属栏目:百科 来源:网络整理
导读:我似乎无法解决在我的attributes / default.rb文件中处理类似命名属性的厨师错误. 我有2个属性: default['test']['webservice']['https']['keyManagerPwd'] = 'password'......default['test']['webservice']['https']['keyManagerPwd']['type'] = 'encrypt
我似乎无法解决在我的attributes / default.rb文件中处理类似命名属性的厨师错误.

我有2个属性:

default['test']['webservice']['https']['keyManagerPwd'] = 'password'
...
...
default['test']['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

请注意,直到最后一个括号([‘type’]),名称是相同的.

我在模板和配方中的模板块中引用这些属性.当我去运行它时,我收到此错误:

==================================================[0m
I,[2015-01-28T13:36:43.668692 #7920]  INFO -- core-14-2-centos-65: 
[31mRecipe Compile Error
in /tmp/kitchen/cache/cookbooks/avx/attributes/default.rb[0m
I,[2015-01-28T13:36:43.669192 #7920]  INFO -- core-14-2-centos-65: 
=================================================================[0m
I,[2015-01-28T13:36:43.669192 #7920]  INFO -- core-14-2-centos-65: 
I,[2015-01-28T13:36:43.669692 #7920]  INFO -- core-14-2-centos-65:    
[0mIndexError[0m
I,[2015-01-28T13:36:43.669692 #7920]  INFO -- core-14-2-centos-65: -------
--[0m
I,[2015-01-28T13:36:43.669692 #7920]  INFO -- core-14-2-centos-65: string not matched[0m
I,[2015-01-28T13:36:43.670192 #7920]  INFO -- core-14-2-centos-65: 
I,[2015-01-28T13:36:43.670192 #7920]  INFO -- core-14-2-centos-65:
[0mCookbook Trace:[0m
I,[2015-01-28T13:36:43.670692 #7920]  INFO -- core-14-2-centos-65: --------[0m
I,[2015-01-28T13:46:05.101875 #8332]  INFO -- core-14-2-centos-65:     
[0m113>> default['webservice']['https']['keyManagerPwd']['type'] = 
'encrypted'

当唯一的区别是结束时,似乎Chef无法区分2个属性.
如果我通过在名称的前面放置一些独特的文本来修改相同的属性,则根本没有配方问题:

default['test']['1']['webservice']['https']['keyManagerPwd'] = 'password'
  ...
  ...
  default['test']['2']['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

通过将[‘1’]和[‘2’]放在那里,它解决了问题.

我对Chef很新,所以我觉得它只是简单的我忽略了.有没有人有任何想法或建议?谢谢.

解决方法

简单回答:你不能这样做.这不是厨师问题,也不是ruby问题 – 这是大多数编程语言的普遍问题.

让我们使用foo作为变量而不是冗长的默认[‘test’] [‘webservice’] [‘https’] [‘keyManagerPwd’].

你有效地做了什么

1: foo = "password"
2: foo['type'] = "encrypted"

在第1行中,foo是一个字符串.在第2行中,它被视为散列(在其他一些语言中称为数组).第二行自动覆盖你的foo =“密码”赋值.它实际上是一样的

1: foo = "password"
2: foo = {}
3: foo['type'] = "encrypted"

替代方案是使用

foo['something'] = "password"
foo['type'] = "encrypted"

或者翻译成你的代码:

default['test']['webservice']['https']['keyManagerPwd']['something'] = 'password'
default['test']['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'

这应该工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读