ENC Puppet DSL with inline_template

380 views
Skip to first unread message

eduardo

unread,
Jun 9, 2012, 9:48:44 AM6/9/12
to Puppet Users
Dear all,

I'm trying to do mass update ssh-accounts by ENC Puppet DSL. I found
great reference in http://jpmens.net/2011/07/25/external-node-classification-and-data-in-puppet/
from Jan-Piet , if anyone had test it may be could help me in a couple
issues.

1) I got "Duplicate definition" error while calling define resource
one{ $user_array: } to workaround I change defined resource like
define one_user($arr) , so to call it one_user{ 'tit': arr => $res } .
Jan-Piet said 'to call my one_user() "function" once for each array
element' , It's essencial for the mass load but How to do it ?.

2) Testing are tell me that input parameter class for
inline_template() has not hash structure instead it is array. Putting
function split in a head of class having unique sense to check for
structure is tell me that parameter is an array not expected string
variable. Why ?

My test , I inserted some comments ## upercase :

class updssh( $users ) {

$users_array = split($users, '[ ;]') ## NO SENSE , ONLY FOR CHECK
$users VARIABLE STRUCTURE

notify{'MSG1': message => "$users" }


$res = inline_template( ## RETURN ARRAY
"<% users.each_with_index do |usr, i| -%>
<% usr.each do |k,v| -%>
<%= k %>:<%= usr[k]['email'] %>:<%= v['type'] %>:<%=
v['key'] %>
<% end -%>
;
<% end -%>")

# Now create an array from that result
$users_array = split($res, '[ ;]') ## $res IS AN ARRAY NOT AN
STRING VARIABLE !!!


#one_user{ $users_array: } ## HOW TO DO IT ??

one_user{ 'tit': ## WORKAROUNT AVOIDING "Duplicate
definition" error
arr => $res ### SAME RETURN FROM INLINE,
}

define one_user($arr) {
## $u = split($title, '[:]')
$u = split($arr, '[:]')

$username = $u[0]
$email = $u[1]
$type = $u[2]

$dd = $u[6]

$msg = sprintf('user=%s, email=%s, type=%s , dd=%s', $username,
$email, $type, $dd)

notify{'MSG': message => "$msg" }

}

}

The ENC data are :

---
parameters: {}

classes:
updssh:
users:
- ppuser7:
type: ssh-rsa
user_auth: JOJOXX
user_ssh: ppuser7
key: XXLLAVEXX_DE_PRUEBA_UPD_SSH_PARA_PPUSER7
email: ppu...@speedy.com
- ppuser8:
type: ssh-rsa
user_ssh: ppuser8
key: LLAVEXX_DE_PRUEBA_UPD_SSH_PARA_PPUSER8
email: ppu...@speedy.com


Any suggestion ?.
Thanks in advanced,
eduardo.

eduardo

unread,
Jun 9, 2012, 10:03:19 AM6/9/12
to Puppet Users
errata for 2) , It should be

Putting function split in a head of class having unique sense to check
for structure is tell me that parameter is an array not expected hash
variable. Why ?

sorry

On 9 jun, 09:48, eduardo <erodr...@gmail.com> wrote:
>   Dear all,
>
>   I'm trying to do mass update ssh-accounts by ENC Puppet DSL. I found
> great reference inhttp://jpmens.net/2011/07/25/external-node-classification-and-data-in...
>         email: ppus...@speedy.com
>     - ppuser8:
>         type: ssh-rsa
>         user_ssh: ppuser8
>         key: LLAVEXX_DE_PRUEBA_UPD_SSH_PARA_PPUSER8
>         email: ppus...@speedy.com

eduardo

unread,
Jun 10, 2012, 12:48:30 PM6/10/12
to Puppet Users
Hi, first of all thanks to Jan-Piet for share it.
My mistake was around shape an inline_template parameter, everything
is ok just deleting linefeeds and spaces characters in it, like this :

-----
$res = inline_template(
"<% users.each do |usr| -%><% usr.each do |k,v| -%><%= k %>:<
%= usr[k]['email'] %>:<%= v['type'] %>:<%= v['key'] %>;<% end -%><%
end -%>")

# Now create an array from that result
$users_array = split($res, '[;]')

one_user{ $users_array: }

define one_user() {
$u = split($title, '[:]')
-----

This way the inline_template parameter is not readable but it's the
way to do it.

Regards,
eduardo.
> >         $res =inline_template(     ## RETURN ARRAY
Reply all
Reply to author
Forward
0 new messages