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

Fix chef_org admin idempotency #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion resources/chef_org.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@
end
end

# TODO: fix idempotency for org admins
org_admins = JSON.parse(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really shouldn't be done by parsing knife. That's going to be super problematic and brittle. You'll want to hit the server API directly and parse out that output from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I was sort of following the pattern of parsing output in some other parts of the same resource but I'll rework it to hit the API.

shell_out(
"/opt/opscode/bin/knife show /groups/admins.json -c /etc/opscode/pivotal.rb --server-url https://127.0.0.1:443/organizations/#{new_resource.org} | grep -v '^/' || echo '{\"users\": []}'"
).stdout
)['users']
new_resource.admins.each do |user|
org_admin_exist = org_admins.include?(user)
execute "add-admin-#{user}-org-#{new_resource.org}" do
command "chef-server-ctl org-user-add --admin #{new_resource.org} #{user}"
only_if { node.run_state['chef-users'].index(/^#{user}$/) }
not_if { org_admin_exist }
end
end

Expand Down