Looping in chef


#1

Ladles & Jellyspoons,
Hello! I have to create a password file for proftpd and am feeling
ambivalent about how to go about it, was hoping someone might help . . .

Proftpd needs to have an olde style passwd file (hashed/crypted passwords
included) to authenticate against. I am currently getting the usernames &
passwords from a data bag and looping through them, checking my password
file to see if they exist and adding if they don’t. A helper method within
a library file is actually doing the work, and I’m wondering if rather than
passing the users to the method one-by-one, if I could be passing the
entire data structure . . . it doesn’t sound like a big difference, but
passing the entire struct back to the helper would make things a log
easier. It doesn’t seem like the chef way, though. But I’m very new to
the chef way.

Puppet had a prased_file provider that made this sort of thing easier, but
this doesn’t seem to exist in chef.

Any thoughts would be appreciated.

Thanks,
Guy


#2

It’s pretty common to pass in the hash from the databag and unpack it in
the erb template, something like this (which is creating a key=value java
properties file, but the idea is the same):

<% @properties.each do | prop| p prop%>
<%= prop[“property”].strip %>=<%= prop[“value”].strip %>
<% end %>

-Peter

On Mon, Nov 4, 2013 at 1:21 PM, Guy Matz guymatz@gmail.com wrote:

Ladles & Jellyspoons,
Hello! I have to create a password file for proftpd and am feeling
ambivalent about how to go about it, was hoping someone might help . . .

Proftpd needs to have an olde style passwd file (hashed/crypted passwords
included) to authenticate against. I am currently getting the usernames &
passwords from a data bag and looping through them, checking my password
file to see if they exist and adding if they don’t. A helper method within
a library file is actually doing the work, and I’m wondering if rather than
passing the users to the method one-by-one, if I could be passing the
entire data structure . . . it doesn’t sound like a big difference, but
passing the entire struct back to the helper would make things a log
easier. It doesn’t seem like the chef way, though. But I’m very new to
the chef way.

Puppet had a prased_file provider that made this sort of thing easier, but
this doesn’t seem to exist in chef.

Any thoughts would be appreciated.

Thanks,
Guy


#3

Thanks!! That will write out the file every time, though . . . Unless I
sort it! Totally! That sounds like the way to go. So far! :slight_smile: Anyone
with a better idea!? :slight_smile:

Thanks again,
Guy

On Mon, Nov 4, 2013 at 1:37 PM, Peter Norton pn+chef-list@knewton.comwrote:

It’s pretty common to pass in the hash from the databag and unpack it in
the erb template, something like this (which is creating a key=value java
properties file, but the idea is the same):

<% @properties.each do | prop| p prop%>
<%= prop[“property”].strip %>=<%= prop[“value”].strip %>
<% end %>

-Peter

On Mon, Nov 4, 2013 at 1:21 PM, Guy Matz guymatz@gmail.com wrote:

Ladles & Jellyspoons,
Hello! I have to create a password file for proftpd and am feeling
ambivalent about how to go about it, was hoping someone might help . . .

Proftpd needs to have an olde style passwd file (hashed/crypted passwords
included) to authenticate against. I am currently getting the usernames &
passwords from a data bag and looping through them, checking my password
file to see if they exist and adding if they don’t. A helper method within
a library file is actually doing the work, and I’m wondering if rather than
passing the users to the method one-by-one, if I could be passing the
entire data structure . . . it doesn’t sound like a big difference, but
passing the entire struct back to the helper would make things a log
easier. It doesn’t seem like the chef way, though. But I’m very new to
the chef way.

Puppet had a prased_file provider that made this sort of thing easier,
but this doesn’t seem to exist in chef.

Any thoughts would be appreciated.

Thanks,
Guy


#4

Yes I am passing in a list so the order is constant between runs. For you a
sort would work as you described.
On Nov 5, 2013 10:21 AM, “Guy Matz” guymatz@gmail.com wrote:

Thanks!! That will write out the file every time, though . . . Unless I
sort it! Totally! That sounds like the way to go. So far! :slight_smile: Anyone
with a better idea!? :slight_smile:

Thanks again,
Guy

On Mon, Nov 4, 2013 at 1:37 PM, Peter Norton pn+chef-list@knewton.comwrote:

It’s pretty common to pass in the hash from the databag and unpack it in
the erb template, something like this (which is creating a key=value java
properties file, but the idea is the same):

<% @properties.each do | prop| p prop%>
<%= prop[“property”].strip %>=<%= prop[“value”].strip %>
<% end %>

-Peter

On Mon, Nov 4, 2013 at 1:21 PM, Guy Matz guymatz@gmail.com wrote:

Ladles & Jellyspoons,
Hello! I have to create a password file for proftpd and am feeling
ambivalent about how to go about it, was hoping someone might help . . .

Proftpd needs to have an olde style passwd file (hashed/crypted
passwords included) to authenticate against. I am currently getting the
usernames & passwords from a data bag and looping through them, checking my
password file to see if they exist and adding if they don’t. A helper
method within a library file is actually doing the work, and I’m wondering
if rather than passing the users to the method one-by-one, if I could be
passing the entire data structure . . . it doesn’t sound like a big
difference, but passing the entire struct back to the helper would make
things a log easier. It doesn’t seem like the chef way, though. But I’m
very new to the chef way.

Puppet had a prased_file provider that made this sort of thing easier,
but this doesn’t seem to exist in chef.

Any thoughts would be appreciated.

Thanks,
Guy