Can you pass vars to a kickstart file that is being read from your packer template?

1,627 views
Skip to first unread message

Aaron Kulbe

unread,
May 29, 2018, 5:13:03 PM5/29/18
to Packer
I'm trying to reuse code as much as I can, but I don't know if you can pass vars to a kickstart file that packer reads from the template.

I have 4 RHEL versions. (7.2 - 7.5). As it stands right now, I have 4 separate templates, 4 kickstart files. I'm wondering if I can pass vars in, and use only one template and one KS file that reads in the values of 

What version I want.
Which ISO to use based on the version.
Which ISO checksum to use, based on the version.

Inside the kickstart file, pin the OS version to that OS's minor release with 
/usr/sbin/subscription-manager release --set=<OS version>


I know it's possible for the packer template file, but can you get the variable value passed into KS file too? If so, how?

Alvaro Miranda Aguilera

unread,
May 29, 2018, 6:29:33 PM5/29/18
to packe...@googlegroups.com
Hello

From a OS point of view all are RHEL7 and you should subscribe to RHEL7 and get all of them up to date.

after upgrade + reboot all the VM will be at the same level, ie won't be 7.2 anymore

having said that, if you want to subscribe a 7.2 to a 7.2 channel, you could parse the lsb_release output



--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/fd5370d3-6a0b-435e-8514-ac8001c6a976%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Rickard von Essen

unread,
May 30, 2018, 4:21:19 AM5/30/18
to packe...@googlegroups.com

Gabo Kete

unread,
May 30, 2018, 3:34:25 PM5/30/18
to Packer
You can use variables, they can be passed in the %pre %post section of your KS file and then used internally, or you can have a script that based on your inputs the KS file is created prior the built via packer. multiple options to avoid having multiple KS files 

If the question is if you can pass variables from packer to the KS file, I do not think that is possible

Gabo Kete

unread,
May 30, 2018, 3:54:07 PM5/30/18
to Packer
almost a year ago did something similar to what you may be after, I face the same challenge and I end up using variables being passed to the KS 

1- I used a wrapper script where the variables were captured and kept to be used later. User entry were  hostname , IP, netmask, etc
2- the script dynamically creates the packer file including these variables, below is an example of the entry for the boot_command

"boot_command": [
        "<tab> text inst.ks=http://{{user \`ks_server\`}}/{{user \`ks_path\`}}/{{user \`ks_file\`}} IP=`echo $_IP` NM=`echo $_NM` GW=`echo $_GW` HN=`echo $_HN` <enter><wait>"

3- Then I captured the /proc/cmdline to identify what the user has passed and based on that, build the machine 
4- I then integrated the whole solution with Jenkins and each and everyone with the right permissions in Jenkins could spin up a CentOS server.. 


I reckon you can do something similar where you capture the version of the Linux you want to build and whatever other option you want to consider and build the machine based on this information.. 


On Wednesday, May 30, 2018 at 9:13:03 AM UTC+12, Aaron Kulbe wrote:
Reply all
Reply to author
Forward
0 new messages