-
Notifications
You must be signed in to change notification settings - Fork 581
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
ensure_packages.rb: Modifed to pass hiera parameters (as hash,array) as first argument #576
Conversation
|
I believe if you want to accomplish this, you can do it in one line: create_resources('package', hiera_hash('packagelist'))Adding resources directly to hiera is very not-recommended though; hiera is for data, and any actionable code should be captured in a manifest such as a "base packages" profile. |
|
Thanks for the contribution, but I think that we prefer to not steer users in this direction. It is still possible to do as I described above, but without over-complicating the exsting |
|
Hi, Thanks for considering, but what I want to achieve is one aspect of ensure_packages(); which is multiple declaration of same packages in different modules even with hiera data check. With above change anyway, existing functionality is intact, it just give provision to run with hiera data as well. Can it be done? |
|
I didnt understand why its rejected ? |
|
Ah, I closed it because I didn't understand that the implied purpose of this PR was to allow this functionality without duplicate conflicts. Looking at it again. |
|
So looking at this from an abstract point, if we take the body of changes you are making to |
|
This sounds a great idea. Keeping ensure_packages() existing functionality will not break anything for any user using it for now. |
| @@ -0,0 +1,70 @@ | |||
| # Test whether a given class or definition is defined | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a copied comment?
|
@yadavnikhil this is a good refactor! I'd also like to see the original scope of the PR included as well, which is refactoring/simplify |
|
@bmjen Hmm. That would cause |
|
Or maybe I'm entirely wrong about how |
|
@bmjen Yes, you right, we can have ensure_packages() to use ensure_resources(). I was under assumption that it will be duplication as we could directly use ensure_resources() for it. But, now i also think we can extend ensure_packages() functionality as well. @hunner Thanks for pointing out that copied comment, I removed it from latest commit. I have modified & committed the code suggested.
Let me know if this will be fine. |
|
@yadavnikhil I think that looks good. Could you add the documentation to the README and squash it to one commit? Thanks! |
|
@hunner As suggested, I've modified the README documentation for this new function & updated usage for ensure_packages() in a single commit. |
|
|
||
| Call: | ||
|
|
||
| `ensure_resources('user', $userlist, {'ensure' => 'present'})` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has to be ensure_resources('user', hiera_hash('userlist'), {'ensure' => 'present'})
|
@hunner Yes, correct. Fixed it. |
| params ||= {} | ||
|
|
||
| if title.is_a?(Hash) | ||
| resource_hash = Hash(title) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry I didn't catch this before, but this appears to be hard tabs. Could you change all indentation to Ruby's standard 2-space indentation?
New function "ensure_resources()" to support passing hash as parameter OR from hiera backend
This new function is extension of ensure_resource() which will now support to pass multiple values as hash/array OR from hiera backend variables in title argument with additional parameters needed.
It will
process multiple values for a resource type from the passed argument & pass each entry (type, title, params) to ensure_resource() in required format for further processing.
Now user can have duplicate resource check functionality extended to multiple entries with this new function.
Use:
For multiple resources using
hash:
ensure_resources('user', {'dan' => { gid => 'mygroup', uid =>'600' } , 'alex' => { gid => 'mygroup' }}, {'ensure' =>'present'})
From Hiera Backend:
userlist:
dan:
gid: 'mygroup'
uid: '600'
alex:
gid: 'mygroup'
Call:
ensure_resources('user',hiera_hash('userlist'), {'ensure' => 'present'})
ensure_packages()
Modified to also support Hash type argument for packages
This modification will call newly added ensure_resources() for processing Hash as second argument.
The original functionality remains same for Array type arguments.
Use:
hiera:
packagelist:
ksh:
ensure: latest
mlocate: {}
myrpm:
provider: rpm
source: "/tmp/myrpm-1.0.0.x86_64.rpm"
install_options:
--prefix:
/users/home
openssl:
provider: rpm
source: "/tmp/openssl-1.0.1e-42.el7.x86_64.rpm"
Call:
ensure_packages($packagelist)
|
@hunner Fixed the mentioned file as suggested. |
ensure_packages.rb: Modifed to pass hiera parameters (as hash,array) as first argument
This change will allow to pass values from hiera backend variables as hash in first argument with additional parameters needed.
Existing implementation did not support this as it considers first argument as array by default. So, if additional parameters were needed from hash, like ex. "providers => rpm" etc, will not work. It will by default pass whole hash value as string to "ensure_resource".
It will merge the hash values for package name (key) with defaults & pass each package name to function_ensure_resource in required format for further processing.
Use:
hiera:
Call:
ensure_packages($packagelist)It will support array by default if first argument in not hash.