Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chown resource executes every run, even when not changing anything #191

Closed
miketheman opened this issue Jul 9, 2015 · 2 comments
Closed
Milestone

Comments

@miketheman
Copy link

We commonly see an execute resource updated every chef run, despite nothing being changed:
Example from our env:

- execute[chown -R root:root /mnt/consul] (consul::_service line 60)
- execute[chown -R root:root /etc/consul.d] (consul::_service line 60)
- execute[chown -R root:root /var/lib/consul] (consul::_service line 60)

This was introduced in #141 - current source.

A better approach is to guard the resource and execute only if necessary, something like:

execute "fixup consul #{dirname}" do
  command "chown -R #{consul_user}:#{consul_group} #{dirname}"
  only_if { Etc.getpwuid(File.stat(dirname).uid).name != "root" }
end

This is untested example code, based on conversations in mailing list and jira ticket tracker from 6 years ago, and the current conditional only applies to the uid, not gid. That should be an easy-enough fix.

Another method would be to use Ruby to get all subdirectories and create resources for each one, but that could lead to unexpected resource creation, if dirname has 10k subdirs - unlikely but possible.

I'd be happy to submit a PR for this, if you're interested in this approach.

/cc: @darron

@johnbellone
Copy link
Contributor

This seems reasonable to me. Feel free to drop a PR and I'll cut another release prior to merging #126.

@johnbellone johnbellone added this to the 0.10.2 milestone Jul 10, 2015
johnbellone pushed a commit that referenced this issue Jul 21, 2015
Prior to this we would always chown directories without checking.
@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants