Creating a config file dynamically based on the group membership of a node
53 views
Skip to first unread message
Grant Street
unread,
May 19, 2014, 7:39:47 AM5/19/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to puppet...@googlegroups.com
Hi
First time poster to this forum. I'm in the process of doing a pilot to convert a cfengine v2 install to puppet.
I was wondering if any one had any ideas on the following.
I have machines that can be in any combination(ie 0 or more) of 10 groups, that can change. I need to create an access.conf based on the group membership of the node. I would like the file to be dynamically created with any redundant lines removed.
I have had a look at augeus but I can't see how to both add lines based on the group as well as remove unwanted and unknown lines. I have also had a look at templates but unsure how that would look like when the you have 0-10 insertion points
Thanks for any tips
Grant
jcbollinger
unread,
May 20, 2014, 2:31:59 PM5/20/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to puppet...@googlegroups.com
A template is probably the way to go. The point to understand there is that you will be templating the entire contents of the file, not just the lines related to the 10 groups. Supposing that you have an array of the names of the wanted groups, then, your template might look like this:
+:root:LOCAL <% @wanted_groups.each do |g| -%> +:(<%= g %>):ALL <% end -%> -:ALL:ALL
John
Grant Street
unread,
May 21, 2014, 4:40:24 AM5/21/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to puppet...@googlegroups.com
Hi John
Thanks a lot for the guidance my solution would have been a whole lot more messy.
I was able to massage your example so that I could use a hash to specify the user and origin like this +:root:LOCAL <% pam_access.each_pair do |user,origin| -%> +:<%= user %>:<%= origin %>
<% end -%> -:ALL:ALL
Now what is the best way to dynamically create the array/hash? I am doing a hash merge at the moment is there a better/more puppet way?
Thanks
Garrett Honeycutt
unread,
May 21, 2014, 4:57:40 AM5/21/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
I have a puppet module[1] for PAM that manages access.conf. You can
specify an array in Hiera with the key pam::allowed_users. Currently it
uses a parameterized class which will look up the value in Hiera and
stop on the first match. The code could be changed to allow for the use
of the hiera_array[2] function which would return all instances found in
Hiera. So if your groups are defined at multiple levels of the
hierarchy, you would want that functionality. Here's an example[3] of
how you might add it. I would be happy to work with you on a pull request.