Making a Provider API Call Idempotent

22 views
Skip to first unread message

Danny Roberts

unread,
Oct 14, 2015, 5:56:16 PM10/14/15
to Puppet Users
In a custom type/provider I am writing it seems that the provider is not entirely idempotent.

The provider (https://github.com/kemra102/puppet-githubapi/blob/master/lib/puppet/provider/github_repo/default.rb) is calling the Github API (https://developer.github.com/v3/repos/#edit) and amending an attribute that is a boolean on the API side is what is causing the issue.

The API always returns a boolean value as expected however the Puppet provider converts the boolean value provided to a symbol and presumably it is this that is causing the value to always be modified even if for example it is already the value specified in the resource.

Notice: Compiled catalog for iacon.cybertron.local in environment production in 0.06 seconds
FalseClass
{"name"=>"apitest", "has_wiki"=>:false}
Symbol
Notice: /Stage[main]/Main/Github_repo[apitest]/has_wiki: has_wiki changed 'false' to 'false'
Notice: Finished catalog run in 2.51 seconds

In the above I added some cheap and dirty debugging which shows;

FalseClass = This is the value returned by the GitHub API.
{"name"=>"apitest", "has_wiki"=>:false} - The values being sent in the body of the request to the GitHub API.
Symbol - As is probably clear this is the class of the 'has_wiki' value.

Any ideas how to correctly match up these values and not cause an unrequired update?

David Schmitt

unread,
Oct 16, 2015, 8:56:28 AM10/16/15
to puppet...@googlegroups.com
Excellent analysis, you've almost solved it.
https://github.com/kemra102/puppet-githubapi/blob/master/lib/puppet/provider/github_repo/default.rb#L78
returns the value from the API. This has to match what puppet receives
from the manifest. Adding '.to_sym' or something similar should fix this.


Cheers, D.

Danny Roberts

unread,
Oct 16, 2015, 1:03:07 PM10/16/15
to Puppet Users

Excellent analysis, you've almost solved it.
https://github.com/kemra102/puppet-githubapi/blob/master/lib/puppet/provider/github_repo/default.rb#L78
returns the value from the API. This has to match what puppet receives
from the manifest. Adding '.to_sym' or something similar should fix this.


Cheers, D.

Thanks that pointed me in the right direction, turns out FalseClass & TrueClass don't have .to_sym but doing .to_s.to_sym works despite how dirty it feels. 
Reply all
Reply to author
Forward
0 new messages