No way to idempotently remove a user #13

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

Comments

Projects
None yet
3 participants
@jaylevitt

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

This comment has been minimized.

Show comment
Hide comment
@davidc-donorschoose

davidc-donorschoose Aug 3, 2012

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

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

This comment has been minimized.

Show comment
Hide comment
@fnichol

fnichol May 23, 2013

Owner

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

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 May 23, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment