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

No way to idempotently remove a user #13

Closed
jaylevitt opened this issue Jul 25, 2012 · 2 comments
Closed

No way to idempotently remove a user #13

jaylevitt opened this issue Jul 25, 2012 · 2 comments

Comments

@jaylevitt
Copy link

If I add

"action": "remove"

to a user's data bag item, the first chef-client run will remove the user--but the second will raise an exception:

ArgumentError: user_account[notanymore] (user::data_bag line 27) had an error: ArgumentError: can't find user for notanymore

Shouldn't remove handle the case where the user's already been removed? Or is there a better way?

@davidc-donorschoose
Copy link

Aha! I was able to remove users idempotently using ignore_failure, which is one of the common attribute that can be set on any resource. I do still see an error such as this in stdout, but it's ignored and the chef-solo run continues:

ERROR: user_account[deleteme] (blueprint::default line 42) had an error: can't find user for deleteme

Example recipe code from my own blueprint cookbook, which depends on the user cookbook, so that I can use the user_account resource:

# Search data_bags/accounts/*.json for users to remove
remove_accounts = search(:users, "(action:remove)")

remove_accounts.each do |u|
  username = u['username'] || u['id']
  user_account username do
    action :remove
    # Idempotent in case the user is already removed.
    ignore_failure true
  end
end

@fnichol
Copy link
Owner

fnichol commented May 23, 2013

Looks like @atz had a great solution in #16 so that should close this out, woo!

@fnichol fnichol closed this as completed May 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants