我有2个属性:
default['test']['webservice']['https']['keyManagerPwd'] = 'password'......default['test']['webservice']['https']['keyManagerPwd']['type'] = 'encrypted'
请注意,直到最后一个括号([‘type’]),名称是相同的.
我在模板和配方中的模板块中引用这些属性.当我去运行它时,我收到此错误:
==================================================[0mI,[2015-01-28T13:36:43.668692 #7920] INFO -- core-14-2-centos-65: [31mRecipe Compile Errorin /tmp/kitchen/cache/cookbooks/avx/attributes/default.rb[0mI,[2015-01-28T13:36:43.669192 #7920] INFO -- core-14-2-centos-65: =================================================================[0mI,[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[0mI,[2015-01-28T13:36:43.669692 #7920] INFO -- core-14-2-centos-65: ---------[0mI,[2015-01-28T13:36:43.669692 #7920] INFO -- core-14-2-centos-65: string not matched[0mI,[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:[0mI,[2015-01-28T13:36:43.670692 #7920] INFO -- core-14-2-centos-65: --------[0mI,[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'
这应该工作.
总结以上是内存溢出为你收集整理的ruby – 关于attributes-字符串不匹配的Chef错误全部内容,希望文章能够帮你解决ruby – 关于attributes-字符串不匹配的Chef错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)