Hi Folks:
I want to something like this in a cobbler kickstart template.
1 #set global users_for_this_vm = () 2 3 #def add_to_list($item) 4 ## Funtion to add to the global user list. 5 users_for_this_vm.append($item) <-- this is where I am confused!! 6 #end def 7 8 ## Define the users for this platform. 9 #set system_name=$getVar($name) 10 #if 'plat01' in $system_name 11 $add_to_list("bob") 12 $add_to_list("ted") 13 $add_to_list("sarah") 14 #elif 'plat02' in $system_name 15 $add_to_list("fred") 16 $add_to_list("wilma") 17 #end if 18 19 #for $user in $users_for_this_vm 20 phase1 $user 21 #end for 22 23 #for $user in $users_for_this_vm 24 setup-special-stuff-that-must-be-done-after-all-users-are-added-in-phase 1 $user 25 #end for
The basic idea is to update a global list with the specific user names for a specific VM so that I can post-process the users after an initial setup. The problem is that I don't know how to append to lists in cheetah.
I suppose that I could do it by updating a shell script variable but I was hoping that there was a way to do it in cheetah. Here is how I might do it using the shell but I wouldn't be able to call cheetah functions.
1 users_for_this_vm=() 2 3 #def add_to_list($item) 4 ## Funtion to add to the global user list. 5 users_for_this_vm=($item $users_for_this_vm) 6 #end def 7 8 ## Define the users for this platform. 9 #set system_name=$getVar($name) 10 #if 'plat01' in $system_name 11 $add_to_list("bob") 12 $add_to_list("ted") 13 $add_to_list("sarah") 14 #elif 'plat02' in $system_name 15 $add_to_list("fred") 16 $add_to_list("wilma") 17 #end if 18 19 for user in ${users_for_this_vm[@]} ; do 20 phase1 $user 21 done 22 23 for user in ${users_for_this_vm[@]} ; do 24 setup-special-stuff-that-must-be-done-after-all-users-are-added-in-phase 1 $user 25 done
Is there a way to accomplish this?
Best regards,
Joe
Hi Folks:
I managed to figure it out. In the hopes that it might be useful to others, here is a snippet that allows you to update a global list of users and then operate on it using cheetah directly.
The trick is to assign the list append operation to a dummy variable.
1 #set global global_users = [] 2 #def add_user($user) 3 ## Function to do user stuff. 4 ## In this case, we are only updating the global variable. 5 ## The trick is to assign the append operation to a dummy variable. 6 #set x = $global_users.append($user) 7 #end def 8 9 #set sysname = $getVar($name) 10 #if 'vm-01' in $sysname 11 $add_user('wombat') 12 $add_user('foo') 13 $add_user('bar') 14 $add_user('spam') 15 #elif 'vm-02' in $sysname 16 $add_user('whiskers') 17 $add_user('fluffy') 18 #end if 19 20 #for user in $global_users 21 setup-phase1 $user 22 #end for 23 24 #for user in $global_users 25 setup-phase2 $user 26 #end for
Regards,
Joe
-----Original Message----- From: Joe Linoff Sent: Tuesday, February 01, 2011 3:46 PM To: cobbler mailing list Cc: Joe Linoff Subject: lists in kickstart templates
Hi Folks:
I want to something like this in a cobbler kickstart template.
1 #set global users_for_this_vm = () 2 3 #def add_to_list($item) 4 ## Funtion to add to the global user list. 5 users_for_this_vm.append($item) <-- this is where I am confused!! 6 #end def 7 8 ## Define the users for this platform. 9 #set system_name=$getVar($name) 10 #if 'plat01' in $system_name 11 $add_to_list("bob") 12 $add_to_list("ted") 13 $add_to_list("sarah") 14 #elif 'plat02' in $system_name 15 $add_to_list("fred") 16 $add_to_list("wilma") 17 #end if 18 19 #for $user in $users_for_this_vm 20 phase1 $user 21 #end for 22 23 #for $user in $users_for_this_vm 24 setup-special-stuff-that-must-be-done-after-all-users-are-added-in-phase 1 $user 25 #end for
The basic idea is to update a global list with the specific user names for a specific VM so that I can post-process the users after an initial setup. The problem is that I don't know how to append to lists in cheetah.
I suppose that I could do it by updating a shell script variable but I was hoping that there was a way to do it in cheetah. Here is how I might do it using the shell but I wouldn't be able to call cheetah functions.
1 users_for_this_vm=() 2 3 #def add_to_list($item) 4 ## Funtion to add to the global user list. 5 users_for_this_vm=($item $users_for_this_vm) 6 #end def 7 8 ## Define the users for this platform. 9 #set system_name=$getVar($name) 10 #if 'plat01' in $system_name 11 $add_to_list("bob") 12 $add_to_list("ted") 13 $add_to_list("sarah") 14 #elif 'plat02' in $system_name 15 $add_to_list("fred") 16 $add_to_list("wilma") 17 #end if 18 19 for user in ${users_for_this_vm[@]} ; do 20 phase1 $user 21 done 22 23 for user in ${users_for_this_vm[@]} ; do 24 setup-special-stuff-that-must-be-done-after-all-users-are-added-in-phase 1 $user 25 done
Is there a way to accomplish this?
Best regards,
Joe
cobbler@lists.fedorahosted.org