Ask Your Question
1

parse a file for data and put it into a variable

asked 2015-02-24 20:02:49 -0500

terencetruong gravatar image

I have a file called "accesslist" which looks like this:

server1:user1,user2,user3
server2:user3
server3:user2,user3

I need to parse this file and depending on the $hostname of the server, it will give me the names of the users. I will put these names into my access.conf file using Puppet DSL and templates. How should I go about parsing the accesslist? Should I write a custom function in Puppet?

Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-02-25 11:24:30 -0500

GregLarkin gravatar image

I believe the better way to achieve this is with Hiera and performing data lookups into the Hiera database from your Puppet code. First, read through the Puppet Hiera documentation.

You can set up a Hiera hierarchy based on, at minimum, the certificate name of each node and then create YAML files like so:

server1.yaml

---
userlist:
  - user1
  - user2
  - user3

server2.yaml

---
userlist:
  - user3

server3.yaml

---
userlist:
  - user2
  - user3

Then your code will look up the value from Hiera and maybe declare the users like so:

$userlist = hiera('userlist')
user { [ $userlist ]:
  ensure => present,
}

Hope that helps!

edit flag offensive delete link more

Comments

@GregLarkin thanks, worked perfectly.

terencetruong gravatar imageterencetruong ( 2015-02-25 18:43:19 -0500 )edit

Excellent, glad to hear it!

GregLarkin gravatar imageGregLarkin ( 2015-02-25 20:38:39 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-02-24 20:02:49 -0500

Seen: 182 times

Last updated: Feb 25 '15