I have a strange problem with using a node attribute that recently had the
value changed.
I have a ruby_block resource that sets a node attribute. The following
mount resource uses that node attribute, but it is getting the old value of
that node attribute, not the new value that was just set by the previous
ruby_block. I’ve tried adding a node.save in that ruby_block, but the
mount resource still gets the old attribute value. Of course, since I did
a node.save, the mount resource gets the new value because it was save on
the previous failed chef run.
Is this expected behavior? I’ve never noticed this before.
Here is the section of code I’m having the issue with. It’s the
node[:ebs][:devicetomount] attribute that I’m having trouble with.
Yes, that is the expected behavior. The block inside the ruby block gets
executed during the converge phase where as the attributes for the mount
resources gets set during the compile phase. So even though the the mount
resource's action gets executed during the converge phase the value of the
attributes for that resource will not get updated after the ruby block's
execution.
You have three possible solutions here:
Change the ruby_block to get executed during compile time if that will
work for you.
Change the logic of mount to be executed as ruby code inside the
ruby_block itself.
I have a strange problem with using a node attribute that recently had the
value changed.
I have a ruby_block resource that sets a node attribute. The following
mount resource uses that node attribute, but it is getting the old value of
that node attribute, not the new value that was just set by the previous
ruby_block. I've tried adding a node.save in that ruby_block, but the
mount resource still gets the old attribute value. Of course, since I did
a node.save, the mount resource gets the new value because it was save on
the previous failed chef run.
Is this expected behavior? I've never noticed this before.
Here is the section of code I'm having the issue with. It's the
node[:ebs][:devicetomount] attribute that I'm having trouble with.
I was considering resorting to saving the value to a file as well, but I
was hoping/praying for a better method than that. I chatted with someone
on Chef Infra (archive) last night and he suggested using a helper method in a library
that just returned the node attribute. I gave this a try, but it didn't
fix the problem. It still returns the old value of the attribute and not
the current value. I'm assuming the library method is also called during
the compile phase, which is why I'm still getting the value of the
attribute before it was changed by a resource.
Anyone else have any suggestions before we resort to saving values in files
so they can be changed and used during a Chef run?
Yes, that is the expected behavior. The block inside the ruby block gets
executed during the converge phase where as the attributes for the mount
resources gets set during the compile phase. So even though the the mount
resource's action gets executed during the converge phase the value of the
attributes for that resource will not get updated after the ruby block's
execution.
You have three possible solutions here:
Change the ruby_block to get executed during compile time if that will
work for you.
Change the logic of mount to be executed as ruby code inside the
ruby_block itself.
I have a strange problem with using a node attribute that recently had
the value changed.
I have a ruby_block resource that sets a node attribute. The following
mount resource uses that node attribute, but it is getting the old value of
that node attribute, not the new value that was just set by the previous
ruby_block. I've tried adding a node.save in that ruby_block, but the
mount resource still gets the old attribute value. Of course, since I did
a node.save, the mount resource gets the new value because it was save on
the previous failed chef run.
Is this expected behavior? I've never noticed this before.
Here is the section of code I'm having the issue with. It's the
node[:ebs][:devicetomount] attribute that I'm having trouble with.
On Thursday, May 23, 2013 at 12:48 AM, Kannan Manickam wrote:
John,
Yes, that is the expected behavior. The block inside the ruby block gets executed during the converge phase where as the attributes for the mount resources gets set during the compile phase. So even though the the mount resource's action gets executed during the converge phase the value of the attributes for that resource will not get updated after the ruby block's execution.
You have three possible solutions here:
Change the ruby_block to get executed during compile time if that will work for you.
Change the logic of mount to be executed as ruby code inside the ruby_block itself.