-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can user variables be used in external files i.e. autounattend.xml #2867
Comments
Hello, At the moment files in http, floppy or uploaded with packer file provisioning are copied as is. At somepoint you may call an powershell script and modify tokens: For examples, have a look here: http://stackoverflow.com/questions/17144355/string-replace-file-content-with-powershell Use (V3 version):
(gc c:\temp\test.txt).replace('[MYID]', 'MyValue') | sc c:\temp\test.txt
Or for V2:
(gc c:\temp\test.txt) -replace '\[MYID\]', 'MyValue' |
thanks @kikitux, that makes sense. |
Hi @michaelosmith - just wondering if you got anywhere with using variables inside autounattend ? I'm using a hacky solution of pre-transforming a templated autounattend file into a temp file that is reference from the packer build command. Works fine - but not very elegant and can lead to the temp file lying around. |
@deluxebrain I'm about to do the same thing. I agree that it is slightly hacky, but it beats having to update the same value across several files every time a change comes along. |
going to close as a dupe of #3961 etc. Will track in a meta-issue I'm creating |
@deluxebrain I managed to solve this by using the following param(
[string]$hostname
)
$ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path
(Get-Content $ScriptDir\answer_files\Autounattend_template.xml).replace('[HOSTNAME]', $hostname) | Set-Content $ScriptDir\answer_files\Autounattend.xml
$exe = "C:\Windows\System32\packer.exe"
&$exe build -var-file="variables.json" -var "vm_name=$hostname" template.json It is just powershell that takes in a hostname parameter (that's all I wanted to change) and then replaces my template value and creates a new Autounattend.xml. I am sure this could be repeated for many different variables. |
I am building windows servers and the flexibility of using user variables is great.
I was wondering if it is possible to apply a user variable into the Autounattend.xml file that is used to automate the setup of windows machines?
The text was updated successfully, but these errors were encountered: