1

Please help me understand if a directory resource idempotent??

I don't find a complete explanation regarding this on Chef Docs except the following information: :create Default. Create a directory. If a directory already exists (but does not match), update that directory to match.

Source: https://docs.chef.io/resource_directory.html

me24hour
  • 629
  • 3
  • 8
  • 15

2 Answers2

3

Idempotent simply means "has no additional effect if it is called more than once with the same input parameters" (What is an idempotent operation?)

If you run a recipe containing a directory resource twice, the 2nd run should have no effect on the directory. For instance the first run of:

directory "#{node.default['jboss']['root']}" do
  owner 'jboss'
  group 'jboss'
  mode '0755'
  action :create
end

will create the directory, if it does not exist, and make sure its owner and group are set to jboss and that permissions on it are '0755'. A second run would do nothing (unless you'd changed any of those things, in which case it would bring it back to that state)

Community
  • 1
  • 1
matt freake
  • 4,877
  • 4
  • 27
  • 56
1

Chef's action names are a bit of a misnomer. The :create action actually means "idempotently ensure that this directory exists and has the given owner/group/mode if provided". It won't actually create it unless needed.

coderanger
  • 52,400
  • 4
  • 52
  • 75