Learner
Learner

Reputation: 162

How to avoid “resource cloning” warning in Chef 12, while using resource which name can't be changed

I know that when I use two resources that have the same name, I might get "deprecated feature used: resource cloning" warning in Chef 12. I could change the name of second resource to avoid resource cloning and get rid of that warning. But what if I can not change resource name? Let's say I have mount at the beginning of my recipe:

mount '/mnt/directory' do
  device "//192.168.1.2/something"
  action [:mount]
end

and then at the end I have umount:

mount '/mnt/directory' do
  device "//192.168.1.2/something"
  action [:umount]
end

I know that this is not common to do both mount and umount in one recipe, but that's my unorthodox way of achieving something. While executing this recipe I get warning about "deprecated feature used: resource cloning". How can I avoid that warning while I can not change the name of second resource, since "/mnt/directory" is the name and I can not change the directory on which the umount will take action?

Upvotes: 1

Views: 199

Answers (1)

Draco Ater
Draco Ater

Reputation: 21226

Every resource in Chef has a so-called name property. The value of this property is taken from the name of the resource, but it also can be overwritten using the explicit property name itself.

For the mount resource the name property is mount_point. If you set mount_point in your resource, it will not matter how you name the resource:

mount 'mount /mnt/directory' do
  mount_point '/mnt/directory'
  device "//192.168.1.2/something"
  action [:mount]
end

mount 'umount /mnt/directory' do
  mount_point '/mnt/directory'
  device "//192.168.1.2/something"
  action [:umount]
end

Upvotes: 1

Related Questions