diff --git a/.gitignore b/.gitignore index cb842e8..4074640 100755 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ gradle.properties wim # packer variable files -/packerfiles/variables*.cfg \ No newline at end of file +/packerfiles/variables_*.pkrvars.hcl +packer_cache/** \ No newline at end of file diff --git a/README.md b/README.md index 9cc002a..8787f14 100755 --- a/README.md +++ b/README.md @@ -1,49 +1,50 @@ -# Example templates for Vagrant and Packer +## Example templates for Vagrant and Packer -## Intro +### Intro There are already some existing GitHub projects providing templates to create machines with Packer. However I created this project for learning purposes . In addition to the packer documentation I also took some inspiration from these great projects: -* https://github.com/kaorimatz/packer-templates -* https://github.com/mwrock/packer-templates -* https://github.com/MattHodge/PackerTemplates -* https://github.com/jacqinthebox/packer-templates - -## Structure - -* [images](https://github.com/papanito/packer-vagrant/tree/master/images) - images for better illustration in the README.txt -* [packerfiles](https://github.com/papanito/packer-vagrant/tree/master/packerfiles) - json and cfg (variables) for packera - * [iso](https://github.com/papanito/packer-vagrant/tree/master/packerfiles/iso) - os specific variables like iso name and checksum - * [scripts](https://github.com/papanito/packer-vagrant/tree/master/packerfiles/scripts) - scripts for provisioning machines with packer -* [scripts](https://github.com/papanito/packer-vagrant/tree/master/scripts) - script to be used for provisioning -* [unattended](https://github.com/papanito/packer-vagrant/tree/master/unattended) - preseed files for Linux and Autounattend files for Windows - * [windows](https://github.com/papanito/packer-vagrant/tree/master/unattended/windows) - autounattended files for Windows +* [kaorimatz: packer-templates](https://github.com/kaorimatz/packer-templates) +* [mwrock: packer-templates](https://github.com/mwrock/packer-templates) +* [MattHodge: PackerTemplates](https://github.com/MattHodge/PackerTemplates) +* [jacqinthebox: packer-templates](https://github.com/jacqinthebox/packer-templates) +* [chef-bento: packer-templates](https://github.com/chef/bento/tree/master/packer_templates) + +### Structure + +* [images](./images) - images for better illustration in the README.txt +* [packerfiles](./packerfiles) - hcl (variables) for packera + * [iso](./packerfiles/iso) - os specific variables like iso name and checksum + * [scripts](./packerfiles/scripts) - scripts for provisioning machines with packer +* [scripts](./scripts) - script to be used for provisioning +* [unattended](./unattended) - preseed files for Linux and Autounattend files for Windows + * [windows](./unattended/windows) - autounattended files for Windows * 10-ent-n-2016-LTSB - Windows 10 Enterprise Edition N2016 LTSB * ... - * [linux](https://github.com/papanito/packer-vagrant/tree/master/unattended/linux) - answer files for Linux + * [linux](./unattended/linux) - answer files for Linux * Ubuntu - Ubuntu specific files * ... -* [vagrantfiles](https://github.com/papanito/packer-vagrant/tree/master/vagrantfiles) +* [vagrantfiles](./vagrantfiles) * @os version@ - Additional information can be found in the related subfolders -## Build +### Build -In order to build VMs with packer you can use the gradle script ```build.gradle``` as follows +In order to build VMs with packer you can use the gradle script `build.gradle` as follows 1. Add a gradle.properties file and define the following values. The values represent tokens which will be replaced in respective answer and packer files - * ```username=@username for user account to be created@``` - * ```password=@password for user account 'username'@``` - * ```rootpassword=@password for root/Administrator account@``` + * `username=@username for user account to be created@` + * `password=@password for user account 'username'@` + * `rootpassword=@password for root/Administrator account@` 2. Define additional parameters - * ```builders=@packer builders to execute e.g. virtualbox-iso@``` + * `builders=@packer builders to execute e.g. virtualbox-iso@` 3. Build machines by calling either `gradle buildLinux -PconfigFile=xxx` or `gradle buildWindows -PconfigFile=xxx`. You have to submit a config file (name form `packerfiles/iso` folder) which defines which distro / windows version to build - ```gradle clean buildWindows -PconfigFile=windows_server_2016_standard_x64.cfg``` + `gradle clean buildWindows -PconfigFile=windows_server_2016_standard_x64.hcl` **Remark: Some characters may break the scripts e.g. using `$` will break `windows-base.ps1`** diff --git a/build.gradle b/build.gradle index cdb06f3..3cf9a52 100755 --- a/build.gradle +++ b/build.gradle @@ -1,24 +1,9 @@ import org.apache.tools.ant.filters.ReplaceTokens -/*task build(type:Exec) { - println "Task build" - //executable = "dir" - //args = [ "packerfiles/iso" ] - //println "call 'gradle buildWindows -PconfigFile=' or 'gradle buildLinux -PconfigFile='" - String osName = System.getProperty("os.name").toLowerCase(); - if (!osName.contains("windows")) { - ext.packer = "packer-io" - } -} -*/ project.ext { packer = 'packer' } -task showConfigs(type:Exec) { - new File("${buildDir}/packerfiles/iso").eachDir{ println it.name } -} - task clean(type: Delete) { delete rootProject.buildDir } @@ -27,18 +12,17 @@ task processResources(type: Copy) { from('unattended') { include '**/*.xml' include '**/*.cfg' - into "unattended" + into "unattended" } from('packerfiles') { - include '**/*.json' - include '**/*.cfg' + include '**/*.hcl' include '**/*.ps1' include '**/*.sh' into 'packerfiles' } filter(ReplaceTokens, tokens: [ - 'username': username, - 'password' : password, + 'username': username, + 'password': password, 'rootpassword': rootpassword ]) into(buildDir) @@ -49,9 +33,9 @@ task buildWindowsBase(type:Exec) { workingDir = buildDir executable = project.ext.packer args = ["build", - "-var-file=./packerfiles/iso/$configFile", - "-var-file=./packerfiles/variables.cfg", - "./packerfiles/windows_1_base.json" ] + "-var-file=./packerfiles/iso/$configFile", + "-var-file=./packerfiles/variables.pkrvars.hcl", + "./packerfiles/windows_1_base.pkr.hcl" ] commandLine } @@ -60,9 +44,9 @@ task buildWindowsUpdates(type:Exec, dependsOn: "buildWindowsBase") { workingDir = buildDir executable = project.ext.packer args = ["build", - "-var-file=./packerfiles/iso/$configFile", - "-var-file=./packerfiles/variables.cfg", - "./packerfiles/windows_2_updates.json" ] + "-var-file=./packerfiles/iso/$configFile", + "-var-file=./packerfiles/variables.pkrvars.hcl", + "./packerfiles/windows_2_updates.pkr.hcl"] commandLine } @@ -71,9 +55,9 @@ task buildWindowsPackages(type:Exec, dependsOn: "buildWindowsUpdates") { workingDir = buildDir executable = project.ext.packer args = ["build", - "-var-file=./packerfiles/iso/$configFile", - "-var-file=./packerfiles/variables.cfg", - "./packerfiles/windows_3_package.json" ] + "-var-file=./packerfiles/iso/$configFile", + "-var-file=./packerfiles/variables.pkrvars.hcl", + "./packerfiles/windows_3_package.pkr.hcl" ] commandLine } @@ -89,11 +73,9 @@ task buildLinux(type:Exec) { workingDir = buildDir executable = project.ext.packer println "Building Linux $configFile at $workingDir" - showConfigs args = ["build", - "-var-file=./packerfiles/iso/$configFile", - "-var-file=./packerfiles/variables.cfg", - "-only=$builders", - "./packerfiles/linux.json" ] + "-var-file=./packerfiles/iso/$configFile", + "-var-file=./packerfiles/variables.pkrvars.hcl", + "./packerfiles/linux.pkr.hcl" ] commandLine } \ No newline at end of file diff --git a/packerfiles/README.md b/packerfiles/README.md index 0082c21..11de251 100644 --- a/packerfiles/README.md +++ b/packerfiles/README.md @@ -1,27 +1,30 @@ -# Introduction +## Introduction -For Linux boxes there is a .json file per OS version (e.g. Ubuntu 17.04 and Ubuntu 16.10). -For Windows boxes there are always at least 3 .json files - base, updates and package - per OS version (e.g. Windows 10, Windows 2016, ...) - this is inspired by [https://hodgkins.io/best-practices-with-packer-and-windows](https://hodgkins.io/best-practices-with-packer-and-windows). +For Linux boxes there is a `.hcl` file per OS version (e.g. Ubuntu 20.01 and Ubuntu 21.04). + +For Windows boxes there are always at least 3 `.hcl` files - base, updates and package - per OS version (e.g. Windows 10, Windows 2016, ...) - this is inspired by [https://hodgkins.io/best-practices-with-packer-and-windows](https://hodgkins.io/best-practices-with-packer-and-windows). For different variations of a system (e.g. Ubuntu Desktop 32-bit or 64-bit, Ubuntu Server, Windows 10 Enterprise 2016 LTSB, Windows 10 Enterprise 2016 N LTSB, ...) I have a separate config file with specific parameters like ISO name and Checksum. So a creation of a base image is called with appropriate -var-file. Example: ```bash -packer build -var-file=iso/windows_10_enterprise_2016_ltsb_en_n_x64.cfg windows_10.json -packer build -var-file=iso/ubuntu_16.10_x64_server.cfg ubuntu_16.10.json +packer build -var-file=iso/windows_10_enterprise_2016_ltsb_en_n_x64.pkrvars.hcl windows_10.hcl +packer build -var-file=iso/ubuntu_16.10_x64_server.pkrvars.hcl ubuntu_16.10.hcl ``` -In additon certain variables defined in the packer files are set to null and therefore should be specified when calling ```packer build```. Mainly this are user credentials and mirrors for e.g. iso files - I keep them on an internal sever which is faster for download than over internet. There is an example config file which I usually copy and modify to my needs. +In addition certain variables defined in the packer files are set to null and therefore should be specified when calling `packer build`. Mainly this are user credentials and mirrors for e.g. iso files - I keep them on an internal sever which is faster for download than over internet. There is an example config file which I usually copy and modify to my needs. ```bash -packer build -var-file=iso/windows_10_enterprise_2016_ltsb_en_n_x64.cfg -var-file=myconfig.cfg windows_10.json -packer build -var-file=iso/ubuntu_16.10_x64_server.cfg -var-file=myconfig.cfg ubuntu_16.10.json +packer build -var-file=iso/windows_10_enterprise_2016_ltsb_en_n_x64.pkrvars.hcl -var-file=myconfig.pkrvars.hcl windows_10.hcl +packer build -var-file=iso/ubuntu_16.10_x64_server.pkrvars.hcl -var-file=myconfig.pkrvars.hcl ubuntu_16.10.hcl ``` -**Remark:** All packer, answer and script files contain ant-like tokens for username and passwords. If you want to manually create the vms as mentioned above, please replace the respective tokens with the desired values. Otherwise, use the gradle script ```build.gradle``` as described [here](https://github.com/papanito/packer-vagrant/tree/master) +> **Remark:** +> +> All packer, answer and script files contain ant-like tokens for username and passwords. If you want to manually create the vms as mentioned above, please replace the respective tokens with the desired values. Otherwise, use the gradle script `build.gradle` as described [here](../README.md) -## Remarks for Linux +### Remarks for Linux -### boot_command +#### boot_command The boot_command is essential to initiate the unattended installation. For Linux systems one has to modify the boot parameters and specify a pre-seed file either by an url or a file location. If taken from a file, is shall be mounted in the vm for example via the floppy @@ -49,28 +52,35 @@ And then used in the boot command as follows Alternatively one can specify an url as follows (replacing "preseed/file"): -```preseed/url=http://artifact-repo/{{user `preseed_name`}}``` +``` +preseed/url=http://artifact-repo/{{user `preseed_name`}} +``` The url can contain a host name or an ip but in case you use an IP you may enabled natdnshostresolver1 on virtualbox: -```["modifyvm", "{{.Name}}", "--natdnshostresolver1", "on"]``` +``` +["modifyvm", "{{.Name}}", "--natdnshostresolver1", "on"] +``` + +#### shutdown_command -### shutdown_command As for any sudo command, it expects a password to be provided unless it is configured passwordless. If not you might have packer stuck at "Gracefully halting virtual machine" and then will timeout (see https://github.com/hashicorp/packer/issues/4813). So my shutdown_command looks like this: -```shutdown_command": "echo '{{user `pwd`}}' | {{user `shutdown_command`}}"``` +``` +shutdown_command": "echo '{{user `pwd`}}' | {{user `shutdown_command`}}" +``` -## Remarks for Windows +### Remarks for Windows -TBD +ISO files and checksum info can be found at [Download Windows 10 Disc Image (ISO File)](https://www.microsoft.com/en-us/software-download/windows10ISO) -# Scripts +## Scripts Scripts for provisioning machines with packer, more details at https://github.com/papanito/packer-vagrant/blob/master/packerfiles/scripts/README.md -# Common Errors and Troubleshooting +## Common Errors and Troubleshooting -## ==> virtualbox-iso: Waiting for WinRM to become available... +### ==> virtualbox-iso: Waiting for WinRM to become available... This may have various reasons but most probably the username and/or password for the user defined in the packer files does not match the one in the answer file. Usually for packer you would pass the password and username by variables as suggested [here](https://www.packer.io/docs/templates/user-variables.html) but you also have the username and password hard-coded in the unattended files. \ No newline at end of file diff --git a/packerfiles/iso/ubuntu_20.04_x64_desktop.cfg b/packerfiles/iso/ubuntu_20.04_x64_desktop.cfg deleted file mode 100755 index 6fe67cc..0000000 --- a/packerfiles/iso/ubuntu_20.04_x64_desktop.cfg +++ /dev/null @@ -1,6 +0,0 @@ -{ - "iso_name": "ubuntu-20.04.2.0-desktop-amd64.iso", - "iso_checksum": "93bdab204067321ff131f560879db46bee3b994bf24836bb78538640f689e58f", - "iso_mirror": "http://releases.ubuntu.com/20.04/", - "iso_checksum_type": "sha256" -} \ No newline at end of file diff --git a/packerfiles/iso/ubuntu_20.04_x64_desktop.pkrvars.hcl b/packerfiles/iso/ubuntu_20.04_x64_desktop.pkrvars.hcl new file mode 100755 index 0000000..8909ea8 --- /dev/null +++ b/packerfiles/iso/ubuntu_20.04_x64_desktop.pkrvars.hcl @@ -0,0 +1,3 @@ +iso_name = "ubuntu-20.04.2.0-desktop-amd64.iso" +iso_checksum = "sha256:93bdab204067321ff131f560879db46bee3b994bf24836bb78538640f689e58f" +iso_mirror" = "http://releases.ubuntu.com/20.04/" \ No newline at end of file diff --git a/packerfiles/iso/ubuntu_20.04_x64_server.cfg b/packerfiles/iso/ubuntu_20.04_x64_server.cfg deleted file mode 100755 index de9db68..0000000 --- a/packerfiles/iso/ubuntu_20.04_x64_server.cfg +++ /dev/null @@ -1,6 +0,0 @@ -{ - "iso_name": "ubuntu-20.04.2-live-server-amd64.iso", - "iso_checksum": "d1f2bf834bbe9bb43faf16f9be992a6f3935e65be0edece1dee2aa6eb1767423", - "iso_mirror": "http://releases.ubuntu.com/20.04/", - "iso_checksum_type": "sha256" -} \ No newline at end of file diff --git a/packerfiles/iso/ubuntu_20.04_x64_server.pkrvars.hcl b/packerfiles/iso/ubuntu_20.04_x64_server.pkrvars.hcl new file mode 100755 index 0000000..633ad88 --- /dev/null +++ b/packerfiles/iso/ubuntu_20.04_x64_server.pkrvars.hcl @@ -0,0 +1,3 @@ +iso_name = "ubuntu-20.04.2-live-server-amd64.iso" +iso_checksum = "sha256:d1f2bf834bbe9bb43faf16f9be992a6f3935e65be0edece1dee2aa6eb1767423" +iso_mirror = "http://releases.ubuntu.com/20.04/" \ No newline at end of file diff --git a/packerfiles/iso/ubuntu_21.04_x64_desktop.cfg b/packerfiles/iso/ubuntu_21.04_x64_desktop.cfg deleted file mode 100755 index 48817b7..0000000 --- a/packerfiles/iso/ubuntu_21.04_x64_desktop.cfg +++ /dev/null @@ -1,6 +0,0 @@ -{ - "iso_name": "ubuntu-21.04-desktop-amd64.iso", - "iso_checksum": "fa95fb748b34d470a7cfa5e3c1c8fa1163e2dc340cd5a60f7ece9dc963ecdf88", - "iso_mirror": "http://releases.ubuntu.com/21.04/", - "iso_checksum_type": "sha256" -} \ No newline at end of file diff --git a/packerfiles/iso/ubuntu_21.04_x64_desktop.pkrvars.hcl b/packerfiles/iso/ubuntu_21.04_x64_desktop.pkrvars.hcl new file mode 100755 index 0000000..6db0010 --- /dev/null +++ b/packerfiles/iso/ubuntu_21.04_x64_desktop.pkrvars.hcl @@ -0,0 +1,3 @@ +iso_name = "ubuntu-21.04-desktop-amd64.iso" +iso_checksum = "sha256:fa95fb748b34d470a7cfa5e3c1c8fa1163e2dc340cd5a60f7ece9dc963ecdf88" +iso_mirror = "http://releases.ubuntu.com/21.04/" \ No newline at end of file diff --git a/packerfiles/iso/ubuntu_21.04_x64_server.cfg b/packerfiles/iso/ubuntu_21.04_x64_server.cfg deleted file mode 100755 index e4348a2..0000000 --- a/packerfiles/iso/ubuntu_21.04_x64_server.cfg +++ /dev/null @@ -1,6 +0,0 @@ -{ - "iso_name": "ubuntu-21.04-live-server-amd64.iso", - "iso_checksum": "e4089c47104375b59951bad6c7b3ee5d9f6d80bfac4597e43a716bb8f5c1f3b0", - "iso_mirror": "http://releases.ubuntu.com/21.04/", - "iso_checksum_type": "sha256" -} \ No newline at end of file diff --git a/packerfiles/iso/ubuntu_21.04_x64_server.pkrvars.hcl b/packerfiles/iso/ubuntu_21.04_x64_server.pkrvars.hcl new file mode 100755 index 0000000..cd0e5fb --- /dev/null +++ b/packerfiles/iso/ubuntu_21.04_x64_server.pkrvars.hcl @@ -0,0 +1,3 @@ +iso_name = "ubuntu-21.04-live-server-amd64.iso" +iso_checksum = "sha256:e4089c47104375b59951bad6c7b3ee5d9f6d80bfac4597e43a716bb8f5c1f3b0" +iso_mirror = "http://releases.ubuntu.com/21.04/" diff --git a/packerfiles/iso/windows_10_20H2_de_x64.pkrvars.hcl b/packerfiles/iso/windows_10_20H2_de_x64.pkrvars.hcl new file mode 100755 index 0000000..46ae5a2 --- /dev/null +++ b/packerfiles/iso/windows_10_20H2_de_x64.pkrvars.hcl @@ -0,0 +1,6 @@ +iso_name = "Win10_20H2_v2_German_x64.iso" +iso_checksum = "sha256:EC1BDCEA7CC1CDD5C31D1D73E3E8708A8E117767FC03F7123AE65A418035224E" +license_key = "XXXXX-XXXXX-XXXXX-XXXXX-XXXX" +guest_os_type = "Windows10_64" +winversion = "10-20h2" +output = "win10-20h2-x64-de" \ No newline at end of file diff --git a/packerfiles/iso/windows_10_20H2_en_x64.pkrvars.hcl b/packerfiles/iso/windows_10_20H2_en_x64.pkrvars.hcl new file mode 100755 index 0000000..5b8cfee --- /dev/null +++ b/packerfiles/iso/windows_10_20H2_en_x64.pkrvars.hcl @@ -0,0 +1,6 @@ +iso_name = "win10_20H2_v2_EnglishInternational_x64.iso" +iso_checksum = "sha256:BD9E41BDF9E23DCF5A0592F3BFE794584C80F1415727ED234E8929F656221836" +license_key = "XXXXX-XXXXX-XXXXX-XXXXX-XXXX" +guest_os_type = "Windows10_64" +winversion = "10-20h2" +output = "win10-20h2-x64" diff --git a/packerfiles/iso/windows_10_enterprise_2016_ltsb_en_x64.cfg b/packerfiles/iso/windows_10_enterprise_2016_ltsb_en_x64.cfg deleted file mode 100755 index 81af376..0000000 --- a/packerfiles/iso/windows_10_enterprise_2016_ltsb_en_x64.cfg +++ /dev/null @@ -1,9 +0,0 @@ -{ - "iso_name": "en_windows_10_enterprise_2016_ltsb_x64_dvd_9059483.iso", - "iso_checksum": "031ED6ACDC47B8F582C781B039F501D83997A1CF", - "iso_checksum_type": "sha1", - "license_key": "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY" - "guest_os_type": "Windows10_64", - "winversion": "10-ent-n-2016-ltsb", - "output": "windows-10-enterprise-ltsb-x64" -} \ No newline at end of file diff --git a/packerfiles/iso/windows_10_enterprise_2016_ltsb_en_x64.pkrvars.hcl b/packerfiles/iso/windows_10_enterprise_2016_ltsb_en_x64.pkrvars.hcl new file mode 100755 index 0000000..6074c87 --- /dev/null +++ b/packerfiles/iso/windows_10_enterprise_2016_ltsb_en_x64.pkrvars.hcl @@ -0,0 +1,6 @@ +iso_name = "en_windows_10_enterprise_2016_ltsb_x64_dvd_9059483.iso" +iso_checksum = "sha1:031ED6ACDC47B8F582C781B039F501D83997A1CF" +license_key = "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY" +guest_os_type = "Windows10_64" +winversion = "10-ent-n-2016-ltsb" +output = "windows-10-enterprise-ltsb-x64" diff --git a/packerfiles/iso/windows_server_2016_standard_x64.cfg b/packerfiles/iso/windows_server_2016_standard_x64.cfg deleted file mode 100755 index d9bc5a7..0000000 --- a/packerfiles/iso/windows_server_2016_standard_x64.cfg +++ /dev/null @@ -1,9 +0,0 @@ -{ - "iso_name": "en_windows_server_2016_x64_dvd_9327751", - "iso_checksum": "91d7b2ebcff099b3557570af7a8a5cd6", - "iso_checksum_type": "md5", - "license_key": "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY", - "guest_os_type": "Windows10_64", - "winversion": "server-2016-std", - "output": "windows-server-2016-standard-x64" -} \ No newline at end of file diff --git a/packerfiles/iso/windows_server_2016_standard_x64.pkrvars.hcl b/packerfiles/iso/windows_server_2016_standard_x64.pkrvars.hcl new file mode 100755 index 0000000..ae0252e --- /dev/null +++ b/packerfiles/iso/windows_server_2016_standard_x64.pkrvars.hcl @@ -0,0 +1,7 @@ +iso_name = "en_windows_server_2016_x64_dvd_9327751" +iso_checksum = "sha256:91d7b2ebcff099b3557570af7a8a5cd6" +iso_checksum_type = "md5" +license_key = "WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY", +guest_os_type = "Windows10_64" +winversion = "server-2016-std" +output = "windows-server-2016-standard-x64" diff --git a/packerfiles/iso/windows_server_2016_storage_x64.cfg b/packerfiles/iso/windows_server_2016_storage_x64.cfg deleted file mode 100755 index 305ebe8..0000000 --- a/packerfiles/iso/windows_server_2016_storage_x64.cfg +++ /dev/null @@ -1,9 +0,0 @@ -{ - "iso_name":"en_windows_storage_server_2016_x64_dvd_9327790", - "iso_checksum": "", - "iso_checksum_type": "", - "license_key": "", - "guest_os_type": "Windows10_64", - "winversion": "server-2016-storage", - "output": "windows-server-2016-storage-x64" -} \ No newline at end of file diff --git a/packerfiles/iso/windows_server_2016_storage_x64.pkrvars.hcl b/packerfiles/iso/windows_server_2016_storage_x64.pkrvars.hcl new file mode 100755 index 0000000..aa1d5ab --- /dev/null +++ b/packerfiles/iso/windows_server_2016_storage_x64.pkrvars.hcl @@ -0,0 +1,7 @@ +iso_name = "en_windows_storage_server_2016_x64_dvd_9327790" +iso_checksum = "sha256:" +iso_checksum_type = " +license_key = " +guest_os_type = "Windows10_64" +winversion = "server-2016-storage" +output = "windows-server-2016-storage-x64" diff --git a/packerfiles/linux.json b/packerfiles/linux.json deleted file mode 100755 index 7cadae0..0000000 --- a/packerfiles/linux.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "variables": { - "aws_access_key": "", - "aws_secret_key": "", - "user": "packer", - "pwd": null, - "ssh_timeout": "2000s", - "iso_name": null, - "iso_mirror": null, - "iso_checksum": null, - "iso_checksum_type": "md5", - "preseed_name": "linux_de-ch_dhcp.cfg", - "shutdown_command": "sudo -S shutdown -P now", - "headless": "true", - "keep_artifacts": "true" - }, - "builders": [ - { - "type": "virtualbox-iso", - "iso_url": "{{user `iso_mirror`}}{{user `iso_name`}}.iso", - "guest_os_type": "Ubuntu_64", - "headless": "{{user `headless`}}", - "iso_checksum": "{{user `iso_checksum`}}", - "iso_checksum_type": "{{user `iso_checksum_type`}}", - "ssh_username": "{{user `user`}}", - "ssh_password": "{{user `pwd`}}", - "ssh_timeout": "{{user `ssh_timeout`}}", - "ssh_pty" : "true", - "boot_wait": "5s", - "boot_command": [ - "", - "", - "", - "/install/vmlinuz initrd=/install/initrd.gz ", - "auto-install/enable=true ", - "debconf/priority=critical ", - "preseed/file=/floppy/unattended/linux/{{user `preseed_name`}} ", - "" - ], - "floppy_dirs": [ - "./unattended/", - "./packerfiles/scripts" - ], - "shutdown_command": "echo '{{user `pwd`}}' | {{user `shutdown_command`}}", - "vboxmanage": [ - ["modifyvm", "{{.Name}}", "--natdnshostresolver1", "on"] - ], - "vm_name": "{{user `iso_name`}}" - }, { - "type": "qemu", - "headless": "{{user `headless`}}", - "iso_url": "{{user `iso_mirror`}}{{user `iso_name`}}.iso", - "iso_checksum": "{{user `iso_checksum`}}", - "iso_checksum_type": "{{user `iso_checksum_type`}}", - "ssh_username": "{{user `user`}}", - "ssh_password": "{{user `pwd`}}", - "ssh_timeout": "{{user `ssh_timeout`}}", - "ssh_pty" : "true", - "boot_wait": "5s", - "boot_command": [ - "", - "", - "", - "/install/vmlinuz initrd=/install/initrd.gz ", - "auto-install/enable=true ", - "debconf/priority=critical ", - "preseed/file=/floppy/unattended/linux/{{user `preseed_name`}} ", - "" - ], - "floppy_dirs": [ - "./unattended/linux", - "./packerfiles/scripts" - ], - "format": "qcow2", - "accelerator": "kvm", - "net_device": "virtio-net", - "disk_interface": "virtio", - "shutdown_command": "echo '{{user `pwd`}}' | {{user `shutdown_command`}}", - "shutdown_timeout": "1m" - } - ], - "provisioners": [ - { - "type": "shell", - "scripts": [ - "packerfiles/scripts/ubuntu.sh" - ] - } - ], - "post-processors": [ - { - "type": "manifest", - "output": "manifest.json", - "strip_path": true - }, - { - "type": "vagrant", - "output": "./boxes/{{user `iso_name`}}/{{user `iso_name`}}-{{.Provider}}.box", - "keep_input_artifact": true - } - ] -} diff --git a/packerfiles/linux.pkr.hcl b/packerfiles/linux.pkr.hcl new file mode 100644 index 0000000..7257622 --- /dev/null +++ b/packerfiles/linux.pkr.hcl @@ -0,0 +1,153 @@ +variable "aws_access_key" { + type = string + default = "" + sensitive = true +} + +variable "aws_secret_key" { + type = string + default = "" + sensitive = true +} + +variable "user" { + type = string + default = "packer" +} + +variable "pwd" { + type = string + default = "ins3CURE" + sensitive = true +} + +variable "iso_mirror" { + type = string +} + +variable "iso_name" { + type = string +} + +variable "iso_checksum" { + type = string +} + +variable "headless" { + type = string + default = "true" +} + +variable "keep_artifacts" { + type = string + default = "true" +} + +variable "preseed_name" { + type = string + default = "linux_de-ch_dhcp.cfg" +} + +variable "shutdown_command" { + type = string + default = "sudo -S shutdown -P now" +} + +variable "ssh_timeout" { + type = string + default = "2000s" +} + +source "qemu" "linux" { + accelerator = "kvm" + boot_command = [ + " ", + " ", + " ", + " ", + " ", + "c", + "", + "set gfxpayload=keep", + "", + "linux /casper/vmlinuz quiet", + " autoinstall", + " ---", + "", + "initrd /casper/initrd", + " preseed/file=/floppy/unattended/linux/${var.preseed_name}", + "", + ] + boot_wait = "5s" + disk_interface = "virtio" + floppy_dirs = [ + "./unattended/linux", + "./packerfiles/scripts" + ] + format = "qcow2" + headless = "${var.headless}" + iso_checksum = "${var.iso_checksum}" + iso_url = "${var.iso_mirror}${var.iso_name}" + net_device = "virtio-net" + shutdown_command = "echo '${var.pwd}' | ${var.shutdown_command}" + shutdown_timeout = "1m" + ssh_password = "${var.pwd}" + ssh_pty = "true" + ssh_timeout = "${var.ssh_timeout}" + ssh_username = "${var.user}" +} + +source "virtualbox-iso" "linux" { + boot_command = [ + " ", + " ", + " ", + " ", + " ", + "c", + "", + "set gfxpayload=keep", + "", + "linux /casper/vmlinuz quiet", + " autoinstall", + " ---", + "", + "initrd /casper/initrd", + " preseed/file=/floppy/unattended/linux/${var.preseed_name}", + "", + "boot" + ] + boot_wait = "5s" + floppy_dirs = [ + "./unattended/", + "./packerfiles/scripts" + ] + guest_os_type = "Ubuntu_64" + headless = "${var.headless}" + iso_checksum = "${var.iso_checksum}" + iso_url = "${var.iso_mirror}${var.iso_name}" + shutdown_command = "echo '${var.pwd}' | ${var.shutdown_command}" + ssh_password = "${var.pwd}" + ssh_pty = "true" + ssh_timeout = "${var.ssh_timeout}" + ssh_username = "${var.user}" + vboxmanage = [["modifyvm", "{{ .Name }}", "--natdnshostresolver1", "on"]] + vm_name = "${var.iso_name}" +} + +build { + sources = [ "source.virtualbox-iso.linux"] + + provisioner "shell" { + scripts = ["packerfiles/scripts/ubuntu.sh"] + } + + post-processor "manifest" { + output = "manifest.json" + strip_path = true + } + post-processor "vagrant" { + keep_input_artifact = true + output = "./boxes/${var.iso_name}/${var.iso_name}.box" + } +} diff --git a/packerfiles/scripts/README.md b/packerfiles/scripts/README.md index 60e913c..f34cd6d 100755 --- a/packerfiles/scripts/README.md +++ b/packerfiles/scripts/README.md @@ -1,4 +1,4 @@ -# Packer script files +## Packer script files These script files are used by packer to create the vms. The scripts are usually provided via the ```floppy_files``` instruction in the packer file as follows - the can be explicitly specified or via wildcard * ```"floppy_files": [ @@ -6,8 +6,8 @@ These script files are used by packer to create the vms. The scripts are usually ], Some of the windows scripts are provided from others, I will add references in the files directly to reflect that. -## Window +### Window Windows scripts are essentially Powershell-Scripts ending with .ps1, but for convenience, I prefixed them with `windows-`. These files are called by the Packer-Provisioner in one of the stages (base, updates or package). `bootstrap.ps1` is an exception as it is called by the unattended process. It's intention is to setup WinRM so that it is usable. -## Linux +### Linux Linux scripts are Bash-Scripts ending with .sh. There are generic scripts like sshconfig.sh and distro-specific files. \ No newline at end of file diff --git a/packerfiles/variables.pkrvars.hcl b/packerfiles/variables.pkrvars.hcl new file mode 100755 index 0000000..45c1929 --- /dev/null +++ b/packerfiles/variables.pkrvars.hcl @@ -0,0 +1,6 @@ +aws_access_key = "" +aws_secret_key = "" +user = "packer" +pwd = "ins3CURE" +keep_artifacts = true +headless = false \ No newline at end of file diff --git a/packerfiles/variables_example.cfg b/packerfiles/variables_example.cfg deleted file mode 100755 index d9682cd..0000000 --- a/packerfiles/variables_example.cfg +++ /dev/null @@ -1,9 +0,0 @@ -{ - "aws_access_key": "", - "aws_secret_key": "", - "user": "@username@", - "pwd": "@password@", - "ssh_timeout": "5m", - "iso_mirror": "http://artifact-repo/iso/", - "keep_artifacts": "false" -}, \ No newline at end of file diff --git a/packerfiles/windows_1_base.json b/packerfiles/windows_1_base.json deleted file mode 100755 index 756de0e..0000000 --- a/packerfiles/windows_1_base.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "builders": [ - { - "type": "virtualbox-iso", - "output_directory": "./output/win{{user `winversion`}}-base/", - "vm_name": "win{{user `winversion`}}-base", - "vboxmanage": [ - [ "modifyvm", "{{.Name}}", "--natpf1", "guest_winrm,tcp,,55985,,5985" ], - [ "modifyvm", "{{.Name}}", "--memory", "2048" ], - [ "modifyvm", "{{.Name}}", "--vram", "128" ], - [ "modifyvm", "{{.Name}}", "--cpus", "1" ] - ], - "guest_additions_mode" : "disable", - "headless": "{{user `headless`}}", - "guest_os_type": "{{user `guest_os_type`}}", - "iso_url": "{{user `iso_mirror`}}//{{user `iso_name`}}.iso", - "iso_checksum_type": "{{user `iso_checksum_type`}}", - "iso_checksum": "{{user `iso_checksum`}}", - "communicator": "winrm", - "winrm_username": "{{user `user`}}", - "winrm_password": "{{user `pwd`}}", - "winrm_timeout": "8h", - "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", - "shutdown_timeout": "15m", - "floppy_files": [ - "./unattended/windows/{{user `winversion`}}/*", - "./unattended/windows/unattend.xml", - "./packerfiles/scripts/*" - ], - "disk_size": "102400" - } - ], - "provisioners": [ - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "script": "./packerfiles/scripts/windows-base.ps1" - } - ], - "variables": { - "user": "vagrant", - "pwd": null, - "iso_name": null, - "iso_mirror": null, - "iso_checksum": null, - "iso_checksum_type": "md5", - "headless": "true", - "keep_artifacts": "false", - "winversion": null - } -} diff --git a/packerfiles/windows_1_base.pkr.hcl b/packerfiles/windows_1_base.pkr.hcl new file mode 100644 index 0000000..5209650 --- /dev/null +++ b/packerfiles/windows_1_base.pkr.hcl @@ -0,0 +1,109 @@ +variable "aws_access_key" { + type = string + default = "" + sensitive = true +} + +variable "aws_secret_key" { + type = string + default = "" + sensitive = true +} + +variable "user" { + type = string + default = "packer" +} + +variable "pwd" { + type = string + default = "ins3CURE" + sensitive = true +} + +variable "iso_mirror" { + type = string + default = "/home/aedu/Downloads/iso/" +} + +variable "headless" { + type = string + default = "true" +} + +variable "keep_artifacts" { + type = string + default = "false" +} + +variable "iso_name" { + type = string +} + +variable "iso_checksum" { + type = string +} + +variable "license_key" { + type = string +} + +variable "guest_os_type" { + type = string +} + +variable "winversion" { + type = string +} + +variable "output" { + type = string +} + +source "qemu" "autogenerated_1" { + accelerator = "kvm" + communicator = "winrm" + disk_size = "102400" + floppy_files = ["./unattended/windows/${var.winversion}/*", "./unattended/windows/unattend.xml", "./packerfiles/scripts/*"] + format = "qcow2" + headless = "${var.headless}" + iso_checksum = "${var.iso_checksum}" + iso_url = "${var.iso_mirror}//${var.iso_name}" + output_directory = "./output/win${var.winversion}-base/" + shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"" + shutdown_timeout = "15m" + vm_name = "win${var.winversion}-base" + winrm_password = "${var.pwd}" + winrm_timeout = "8h" + winrm_username = "${var.user}" +} + +source "virtualbox-iso" "autogenerated_2" { + communicator = "winrm" + disk_size = "102400" + floppy_files = ["./unattended/windows/${var.winversion}/*", "./unattended/windows/unattend.xml", "./packerfiles/scripts/*"] + guest_additions_mode = "disable" + guest_os_type = "${var.guest_os_type}" + headless = "${var.headless}" + iso_checksum = "${var.iso_checksum}" + iso_url = "${var.iso_mirror}/${var.iso_name}" + output_directory = "./output/win${var.winversion}-base/" + shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"" + shutdown_timeout = "15m" + vboxmanage = [["modifyvm", "{{ .Name }}", "--natpf1", "guest_winrm,tcp,,55985,,5985"], ["modifyvm", "{{ .Name }}", "--memory", "2048"], ["modifyvm", "{{ .Name }}", "--vram", "128"], ["modifyvm", "{{ .Name }}", "--cpus", "1"]] + vm_name = "win${var.winversion}-base" + winrm_password = "${var.pwd}" + winrm_timeout = "8h" + winrm_username = "${var.user}" +} + +build { + sources = ["source.virtualbox-iso.autogenerated_2"] + + provisioner "powershell" { + elevated_password = "${var.pwd}" + elevated_user = "${var.user}" + script = "./packerfiles/scripts/windows-base.ps1" + } + +} diff --git a/packerfiles/windows_2_updates.json b/packerfiles/windows_2_updates.json deleted file mode 100755 index b5b358b..0000000 --- a/packerfiles/windows_2_updates.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "builders": [ - { - "type": "virtualbox-ovf", - "source_path": "./output/win{{user `winversion`}}-base/win{{user `winversion`}}-base.ovf", - "output_directory": "./output/win{{user `winversion`}}-updates/", - "vm_name": "win{{user `winversion`}}-updates", - "vboxmanage": [ - [ "modifyvm", "{{.Name}}", "--memory", "2048" ], - [ "modifyvm", "{{.Name}}", "--vram", "128" ], - [ "modifyvm", "{{.Name}}", "--cpus", "1" ] - ], - "guest_additions_mode" : "disable", - "headless": true, - "communicator": "winrm", - "winrm_username": "{{user `user`}}", - "winrm_password": "{{user `pwd`}}", - "winrm_timeout": "12h", - "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"", - "shutdown_timeout": "1h" - } - ], - "provisioners": [ - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "script": "./packerfiles/scripts/windows-updates.ps1" - }, - { - "type": "windows-restart", - "restart_timeout": "1h" - }, - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "inline": ["Get-WUInstall -MicrosoftUpdate -AcceptAll -IgnoreReboot"] - }, - { - "type": "windows-restart", - "restart_timeout": "1h" - }, - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "inline": ["Get-WUInstall -MicrosoftUpdate -AcceptAll -IgnoreReboot"] - }, - { - "type": "windows-restart", - "restart_timeout": "1h" - } - ] -} \ No newline at end of file diff --git a/packerfiles/windows_2_updates.pkr.hcl b/packerfiles/windows_2_updates.pkr.hcl new file mode 100644 index 0000000..9466409 --- /dev/null +++ b/packerfiles/windows_2_updates.pkr.hcl @@ -0,0 +1,50 @@ + +source "virtualbox-ovf" "autogenerated_1" { + communicator = "winrm" + guest_additions_mode = "disable" + headless = true + output_directory = "./output/win${var.winversion}-updates/" + shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"" + shutdown_timeout = "1h" + source_path = "./output/win${var.winversion}-base/win${var.winversion}-base.ovf" + vboxmanage = [["modifyvm", "{{ .Name }}", "--memory", "2048"], ["modifyvm", "{{ .Name }}", "--vram", "128"], ["modifyvm", "{{ .Name }}", "--cpus", "1"]] + vm_name = "win${var.winversion}-updates" + winrm_password = "${var.pwd}" + winrm_timeout = "12h" + winrm_username = "${var.user}" +} + +build { + sources = ["source.virtualbox-ovf.autogenerated_1"] + + provisioner "powershell" { + elevated_password = "${var.pwd}" + elevated_user = "${var.user}" + script = "./packerfiles/scripts/windows-updates.ps1" + } + + provisioner "windows-restart" { + restart_timeout = "1h" + } + + provisioner "powershell" { + elevated_password = "${var.pwd}" + elevated_user = "${var.user}" + inline = ["Get-WUInstall -MicrosoftUpdate -AcceptAll -IgnoreReboot"] + } + + provisioner "windows-restart" { + restart_timeout = "1h" + } + + provisioner "powershell" { + elevated_password = "${var.pwd}" + elevated_user = "${var.user}" + inline = ["Get-WUInstall -MicrosoftUpdate -AcceptAll -IgnoreReboot"] + } + + provisioner "windows-restart" { + restart_timeout = "1h" + } + +} diff --git a/packerfiles/windows_3_package.json b/packerfiles/windows_3_package.json deleted file mode 100755 index 5db9995..0000000 --- a/packerfiles/windows_3_package.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "builders": [ - { - "type": "virtualbox-ovf", - "source_path": "./output/win{{user `winversion`}}-updates/win{{user `winversion`}}-updates.ovf", - "output_directory": "./output/win{{user `winversion`}}-package/", - "vm_name": "win{{user `winversion`}}-package", - "vboxmanage": [ - [ "modifyvm", "{{.Name}}", "--memory", "2048" ], - [ "modifyvm", "{{.Name}}", "--vram", "128" ], - [ "modifyvm", "{{.Name}}", "--cpus", "1" ] - ], - "guest_additions_mode" : "attach", - "headless": true, - "communicator": "winrm", - "winrm_username": "{{user `user`}}", - "winrm_password": "{{user `pwd`}}", - "winrm_timeout": "12h", - "shutdown_command": "C:/Scripts/sysprep.cmd", - "shutdown_timeout": "1h", - "floppy_files": [ - "./packerfiles/scripts" - ] - } - ], - "provisioners": [ - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "script": "./packerfiles/scripts/windows-tools_and_stuff.ps1" - }, - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "script": "./packerfiles/scripts/import-certificate.ps1" - }, - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "script": "./packerfiles/scripts/windows-configurewinrm.ps1" - }, - { - "type": "windows-restart", - "restart_timeout": "1h" - }, - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "script": "./packerfiles/scripts/windows-compress.ps1" - } - ], - "post-processors": [ - { - "type": "vagrant", - "keep_input_artifact": true, - //"vagrantfile_template": "./templates/vagrantfile-windows-10.template", - "output": "{{user `output`}}.box" - } - ] -} diff --git a/packerfiles/windows_3_package.pkr.hcl b/packerfiles/windows_3_package.pkr.hcl new file mode 100644 index 0000000..924637c --- /dev/null +++ b/packerfiles/windows_3_package.pkr.hcl @@ -0,0 +1,53 @@ + +source "virtualbox-ovf" "autogenerated_1" { + communicator = "winrm" + floppy_files = ["./packerfiles/scripts"] + guest_additions_mode = "attach" + headless = true + output_directory = "./output/win${var.winversion}-package/" + shutdown_command = "C:/Scripts/sysprep.cmd" + shutdown_timeout = "1h" + source_path = "./output/win${var.winversion}-updates/win${var.winversion}-updates.ovf" + vboxmanage = [["modifyvm", "{{ .Name }}", "--memory", "2048"], ["modifyvm", "{{ .Name }}", "--vram", "128"], ["modifyvm", "{{ .Name }}", "--cpus", "1"]] + vm_name = "win${var.winversion}-package" + winrm_password = "${var.pwd}" + winrm_timeout = "12h" + winrm_username = "${var.user}" +} + +build { + sources = ["source.virtualbox-ovf.autogenerated_1"] + + provisioner "powershell" { + elevated_password = "${var.pwd}" + elevated_user = "${var.user}" + script = "./packerfiles/scripts/windows-tools_and_stuff.ps1" + } + + provisioner "powershell" { + elevated_password = "${var.pwd}" + elevated_user = "${var.user}" + script = "./packerfiles/scripts/import-certificate.ps1" + } + + provisioner "powershell" { + elevated_password = "${var.pwd}" + elevated_user = "${var.user}" + script = "./packerfiles/scripts/windows-configurewinrm.ps1" + } + + provisioner "windows-restart" { + restart_timeout = "1h" + } + + provisioner "powershell" { + elevated_password = "${var.pwd}" + elevated_user = "${var.user}" + script = "./packerfiles/scripts/windows-compress.ps1" + } + + post-processor "vagrant" { + keep_input_artifact = true + output = "${var.output}.box" + } +} diff --git a/packerfiles/windows_server_2016_4_iis.json b/packerfiles/windows_server_2016_4_iis.json deleted file mode 100755 index 3125535..0000000 --- a/packerfiles/windows_server_2016_4_iis.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "builders": [ - { - "type": "virtualbox-ovf", - "source_path": "./output/win2016-package/vbox-win2016-package.ovf", - "output_directory": "./output/win2016-package-iis/", - "vm_name": "vbox-win2016-package-iis", - "headless": true, - "guest_additions_mode": "disable", - "vboxmanage": [ - [ "modifyvm", "{{.Name}}", "--memory", "2048" ], - [ "modifyvm", "{{.Name}}", "--vram", "128" ], - [ "modifyvm", "{{.Name}}", "--cpus", "1" ] - ], - "communicator": "winrm", - "winrm_username": "{{user `user`}}", - "winrm_password": "{{user `pwd`}}", - "winrm_timeout": "12h", - "shutdown_command": "C:/Scripts/sysprep.cmd", - "shutdown_timeout": "1h" - } - ], - "provisioners": [ - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "script": "./scripts/windows-iis.ps1" - }, - { - "type": "windows-restart", - "restart_timeout": "1h" - }, - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "script": "./scripts/windows-updates.ps1" - }, - { - "type": "windows-restart", - "restart_timeout": "1h" - }, - { - "type": "powershell", - "elevated_user": "{{user `user`}}", - "elevated_password": "{{user `pwd`}}", - "script": "./scripts/windows-compress.ps1" - } - ], - "post-processors": [ - { - "type": "vagrant", - "keep_input_artifact": true, - "output": "windows-2016-server-standard-iis.box", - "vagrantfile_template": "./templates/vagrantfile-windows-2016-iis.template" - } - ] -} diff --git a/unattended/README.md b/unattended/README.md index 3a51d9a..f94b4dd 100644 --- a/unattended/README.md +++ b/unattended/README.md @@ -1,19 +1,27 @@ -# Introduction to Unattendend Installation -More infos on how to create unattended installation for Windows and Linux can be found on my blog: -https://wyssmann.com/unattended/ +## Introduction to Unattendend Installation + +More infos on how to create unattended installation for Windows and Linux can be found on my [blog](https://wyssmann.com/blog/2017/04/unattended-installation-of-linux-and-windows/) + +### Linux -# Linux Files follow simple naming convention: -```____cfg``` -# Windows +``` +__>_x64|x32_.pkrvars.hcl +``` + +### Windows + There are two ways to map the unattended files on floppy: + ``` "floppy_dirs": [ "unattended/windows/server-2016-std/*" ] ``` + Keep attention to use the wildcard * otherwise unattended installation will not kick in. Alternatively you can map the files individually + ``` "floppy_files": [ "unattended/windows/server-2016-std/Autounattend.xml", diff --git a/unattended/linux/linux_de-ch_dhcp.cfg b/unattended/linux/linux_de-ch_dhcp.cfg index 38d02d5..93005b1 100644 --- a/unattended/linux/linux_de-ch_dhcp.cfg +++ b/unattended/linux/linux_de-ch_dhcp.cfg @@ -46,7 +46,9 @@ d-i mirror/http/hostname string archive.ubuntu.com d-i mirror/http/directory string /ubuntu d-i mirror/http/proxy string -# Alternatively: by default, the installer uses CC.archive.ubuntu.com where +# Alternatively { + type = string + default = by default, the installer uses CC.archive.ubuntu.com where # CC is the ISO-3166-2 code for the selected country. You can preseed this # so that it does so without asking. #d-i mirror/http/mirror select CC.archive.ubuntu.com @@ -106,9 +108,15 @@ d-i clock-setup/ntp boolean true ### Partitioning # The presently available methods are: -# - regular: use the usual partition types for your architecture -# - lvm: use LVM to partition the disk -# - crypto: use LVM within an encrypted partition +# - regular { + type = string + default = use the usual partition types for your architecture +# - lvm { + type = string + default = use LVM to partition the disk +# - crypto { + type = string + default = use LVM within an encrypted partition d-i partman-auto/method string lvm # If one of the disks that are going to be automatically partitioned @@ -128,9 +136,15 @@ d-i partman-lvm/confirm_nooverwrite boolean true #d-i partman-auto-lvm/guided_size string 50% # You can choose one of the three predefined partitioning recipes: -# - atomic: all files in one partition -# - home: separate /home partition -# - multi: separate /home, /var, and /tmp partitions +# - atomic { + type = string + default = all files in one partition +# - home { + type = string + default = separate /home partition +# - multi { + type = string + default = separate /home, /var, and /tmp partitions d-i partman-auto/choose_recipe select atomic # If you just want to change the default filesystem from ext3 to something @@ -163,7 +177,9 @@ d-i apt-setup/security_path string /ubuntu # By default the installer requires that repositories be authenticated # using a known gpg key. This setting can be used to disable that -# authentication. Warning: Insecure, not recommended. +# authentication. Warning { + type = string + default = Insecure, not recommended. #d-i debian-installer/allow_unauthenticated boolean true ### Package selection @@ -172,7 +188,9 @@ tasksel tasksel/first multiselect ubuntu-server ubuntu-standard # Individual additional packages to install d-i pkgsel/include string openssh-server build-essential # Whether to upgrade packages after debootstrap. -# Allowed values: none, safe-upgrade, full-upgrade +# Allowed values { + type = string + default = none, safe-upgrade, full-upgrade d-i pkgsel/upgrade select safe-upgrade ### Boot loader installation @@ -183,6 +201,8 @@ d-i grub-installer/only_debian boolean true d-i finish-install/reboot_in_progress note d-i preseed/late_command string \ - echo '@username@ ALL=(ALL) NOPASSWD: ALL' > /target/etc/sudoers.d/@username@ ; \ + echo '@username@ ALL=(ALL) NOPASSWD { + type = string + default = ALL' > /target/etc/sudoers.d/@username@ ; \ in-target chmod 440 /etc/sudoers.d/@username@ ; #d-i preseed/late_command string in-target sed -i 's/PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config \ No newline at end of file diff --git a/unattended/windows/README.md b/unattended/windows/README.md index df46124..60eb2c2 100644 --- a/unattended/windows/README.md +++ b/unattended/windows/README.md @@ -1,36 +1,45 @@ -# General +## General For general information checkout https://github.com/papanito/packer-vagrant -# Answer file generation +## Answer file generation + Due to the complex structure of answer files you shall use tools for that, the Windows System Image Manager (Windows SIM) – which is part of the [https://developer.microsoft.com/en-us/windows/hardware/windows-assessment-deployment-kit](Windows Assessment and Deployment Kit). Keys in WIM (source: http://www.msfn.org/board/topic/88048-amd64-wow64-x86-in-the-wsim/) + * amd_64 - 64bit components, only used on x64 installs * wow_64 - 32bit components or support components for 32bit compat installed on x64, only used on x64 installs * x86 - 32bit components installed on x86, only used on x86 installs As windows relies on a fixed name "Unattend.xml" or "Autounattended.xml" respectively, they are divided in sub folders (1 per Windows version). You may wonder why you may need two files, I recommend read trough https://technet.microsoft.com/en-us/library/cc749415(v=ws.10).aspx + > As a rule, only answer files named Unattend.xml are used. However, because some answer files include destructive actions such as disk partitioning, you must rename your Unattend.xml file to Autounattend.xml in the windowsPE and offlineServicing configuration passes. These passes run when you first run Windows PE or Setup.exe. You typically use the Autounattend.xml file when you use the Windows Setup DVD boot method and supply an answer file on a USB flash drive (UFD) or floppy disk. More info to language locales: + https://msdn.microsoft.com/en-us/library/dd318693(v=vs.85).aspx More info to timezone identifiers: + https://msdn.microsoft.com/en-us/library/ms912391%28v=winembedded.11%29.aspx?f=255&MSPPError=-2147217396 -# Passes +## Passes + The file is divided in different sections called “Configuration passes” and are used to specify different phases of the Windows Setup. More info to this can be found at MSDN: * https://msdn.microsoft.com/en-us/windows/hardware/commercialize/manufacture/desktop/how-configuration-passes-work * https://msdn.microsoft.com/en-us/windows/hardware/commercialize/manufacture/desktop/automate-windows-setup ![alt text](https://i-msdn.sec.s-msft.com/en-us/windows/hardware/commercialize/manufacture/desktop/images/dep-win8-l-configpassesandexes.jpg "configuration passes") -## windowsPE +### windowsPE + https://msdn.microsoft.com/en-us/windows/hardware/commercialize/manufacture/desktop/windowspe This pass is triggered when booting the Windows Setup media (.iso). As we don't use a [Windows PE](https://msdn.microsoft.com/en-us/windows/hardware/commercialize/manufacture/desktop/winpe-intro) we do not need Windows PE options but only Windows Setup options. So this is what we do: -### Partition and format a hard disk. + +#### Partition and format a hard disk. + Reference: https://msdn.microsoft.com/en-us/windows/hardware/commercialize/customize/desktop/unattend/microsoft-windows-setup-diskconfiguration We create a single NTFS partition with a size of 80GB @@ -38,12 +47,14 @@ We create a single NTFS partition with a size of 80GB Tips: Order: starting with 1 and increasing https://msdn.microsoft.com/en-us/windows/hardware/commercialize/customize/desktop/unattend/microsoft-windows-setup-diskconfiguration-disk-createpartitions-createpartition -### Windows image and target partition +#### Windows image and target partition + Reference: https://msdn.microsoft.com/en-us/windows/hardware/commercialize/customize/desktop/unattend/microsoft-windows-setup-imageinstall-osimage First step is to select a specific Windows image to install, the path of that image, and any credentials required to access that image. We use the image provided with the iso. So no credentials needed. Second step is to select a partition on the destination computer where you install Windows. We only have one partition so we use this. -``` + +```xml @@ -59,48 +70,60 @@ Second step is to select a partition on the destination computer where you insta ``` -### Apply a product key and administrator password. + +#### Apply a product key and administrator password. + Reference: https://msdn.microsoft.com/en-us/windows/hardware/commercialize/customize/desktop/unattend/microsoft-windows-setup-userdata Product keys for Windows eventually need to be updated. I currently use the ones mentioned here: http://technet.microsoft.com/en-us/library/jj612867.aspx -### Run specific commands during Windows Setup. -References: +#### Run specific commands during Windows Setup. + +References: + * https://msdn.microsoft.com/en-us/windows/hardware/commercialize/customize/desktop/unattend/microsoft-windows-setup-runsynchronous * https://msdn.microsoft.com/en-us/windows/hardware/commercialize/customize/desktop/unattend/microsoft-windows-setup-runasynchronous + During setup no commands will be executed. We will do this later. -## offline Servicing +### offline Servicing Reference https://msdn.microsoft.com/en-us/windows/hardware/commercialize/customize/desktop/unattend/microsoft-windows-shell-setup-offlineuseraccounts -## oobeSytem (Out-Of-the-Box-Experience) +### oobeSytem (Out-Of-the-Box-Experience) + Reference: https://msdn.microsoft.com/en-us/windows/hardware/commercialize/manufacture/desktop/oobesystem It runs the first time the user starts a newly configured computer and before a user first logs on to Windows®. -# Common Errors and Troubleshooting +## Common Errors and Troubleshooting + Unfortunately the validation of the Windows System Image Manager does not point out all possible issues. So it is sometimes a trial and error until you get a working answer file. -## Windows cannot parse the unattend answer file's setting +### Windows cannot parse the unattend answer file's setting + Some settings just don't go together unfortunately with this message it is not really clear what's wrong. + * often empty values cause this problem so instead remove settingsnot used by "Revert changes". The difference of both is "Revert changes" also removes the tag in the xml while with an empty value there is still a tag in the xml * I tried TypeID "Primary" in in the [Configuration > Disk > Modify Partition](https://msdn.microsoft.com/en-us/windows/hardware/commercialize/customize/desktop/unattend/microsoft-windows-setup-diskconfiguration-disk-modifypartitionsDisk) but unfortunatley it caused the error. Removing it solved it. +### "Select OS" dialog is shown -## "Select OS" dialog is shown Unattended installation stopped quite early and showd "Select OS" screen. This is caused if no image source is specified. -## "Get Going Fast" page opens during setup +### "Get Going Fast" page opens during setup + This happens if there is no default valueset for [ProtectYourPC](https://msdn.microsoft.com/en-us/windows/hardware/commercialize/customize/desktop/unattend/microsoft-windows-shell-setup-oobe-protectyourpc?f=255&MSPPError=-2147217396) -## "Other user" is shwon after first login +### "Other user" is shwon after first login + ... -## User is not administrator -You missed to specify the "group" in the "Offline User Accounts" settings. -``` +### User is not administrator +You missed to specify the "group" in the "Offline User Accounts" settings. + +```xml ... @@ -109,7 +132,7 @@ You missed to specify the "group" in the "Offline User Accounts" settings. ``` -## Problems parsing unattend file +### Problems parsing unattend file Under certain circumstances you may get the following or a similar error after first reboot of the unattended installation: ``` diff --git a/vagrantfiles/ubuntu_16.10_x64/Vagrantfile b/vagrantfiles/ubuntu_16.10_x64/Vagrantfile deleted file mode 100644 index 4cbac11..0000000 --- a/vagrantfiles/ubuntu_16.10_x64/Vagrantfile +++ /dev/null @@ -1,71 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -# All Vagrant configuration is done below. The "2" in Vagrant.configure -# configures the configuration version (we support older styles for -# backwards compatibility). Please don't change it unless you know what -# you're doing. -Vagrant.configure("2") do |config| - # The most common configuration options are documented and commented below. - # For a complete reference, please see the online documentation at - # https://docs.vagrantup.com. - - # Every Vagrant development environment requires a box. You can search for - # boxes at https://atlas.hashicorp.com/search. - config.vm.box_url = "file://../../boxes/ubuntu-16.10-server-amd64/ubuntu-16.10-server-amd64-virtualbox.box" - - # Disable automatic box update checking. If you disable this, then - # boxes will only be checked for updates when the user runs - # `vagrant box outdated`. This is not recommended. - # config.vm.box_check_update = false - - # Create a forwarded port mapping which allows access to a specific port - # within the machine from a port on the host machine. In the example below, - # accessing "localhost:8080" will access port 80 on the guest machine. - # config.vm.network "forwarded_port", guest: 80, host: 8080 - - # Create a private network, which allows host-only access to the machine - # using a specific IP. - # config.vm.network "private_network", ip: "192.168.33.10" - - # Create a public network, which generally matched to bridged network. - # Bridged networks make the machine appear as another physical device on - # your network. - # config.vm.network "public_network" - - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - # config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - config.vm.provider "virtualbox" do |vb| - # Display the VirtualBox GUI when booting the machine - vb.gui = true - - # Customize the amount of memory on the VM: - vb.memory = "2048" - end - # - # View the documentation for the provider you are using for more - # information on available options. - - # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies - # such as FTP and Heroku are also available. See the documentation at - # https://docs.vagrantup.com/v2/push/atlas.html for more information. - # config.push.define "atlas" do |push| - # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" - # end - - # Enable provisioning with a shell script. Additional provisioners such as - # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the - # documentation for more information about their specific syntax and use. - # config.vm.provision "shell", inline: <<-SHELL - # apt-get update - # apt-get install -y apache2 - # SHELL -end diff --git a/vagrantfiles/ubuntu_16.10_x64_atlas/Vagrantfile b/vagrantfiles/ubuntu_16.10_x64_atlas/Vagrantfile deleted file mode 100644 index b7c102e..0000000 --- a/vagrantfiles/ubuntu_16.10_x64_atlas/Vagrantfile +++ /dev/null @@ -1,21 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -Vagrant.configure("2") do |config| - config.vm.box = "ubuntu/yakkety64" - config.vm.hostname = "docker-host" - - config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" - config.vm.network "private_network", ip: "192.168.33.10" - - # Share an additional folder to the guest VM - config.vm.synced_folder "../data", "/vagrant_data" - - # Provider-specific configuration - config.vm.provider "virtualbox" do |vb| - vb.memory = "2048" - end - - config.vm.provision "shell", path: "../scripts/docker.sh" - config.vm.provision "file", source: "../../index.html", destination: "/var/www/index.html" -end diff --git a/vagrantfiles/ubuntu_16.04_x64/Vagrantfile b/vagrantfiles/ubuntu_19.04_x64/Vagrantfile old mode 100644 new mode 100755 similarity index 70% rename from vagrantfiles/ubuntu_16.04_x64/Vagrantfile rename to vagrantfiles/ubuntu_19.04_x64/Vagrantfile index 592863d..76cab4e --- a/vagrantfiles/ubuntu_16.04_x64/Vagrantfile +++ b/vagrantfiles/ubuntu_19.04_x64/Vagrantfile @@ -12,7 +12,7 @@ Vagrant.configure("2") do |config| # Every Vagrant development environment requires a box. You can search for # boxes at https://atlas.hashicorp.com/search. - config.vm.box = "ubuntu/xenial64" + config.vm.box = "ubuntu/zesty64" # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs @@ -57,7 +57,7 @@ Vagrant.configure("2") do |config| # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies # such as FTP and Heroku are also available. See the documentation at # https://docs.vagrantup.com/v2/push/atlas.html for more information. - # config.push.define "atlas" do |push| + # config.push.define "atlas" do |push|sudo virsh net-start default # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" # end @@ -68,4 +68,33 @@ Vagrant.configure("2") do |config| # apt-get update # apt-get install -y apache2 # SHELL -end + + config.vm.provider :libvirt do |libvirt| + + # A hypervisor name to access. Different drivers can be specified, but + # this version of provider creates KVM machines only. Some examples of + # drivers are kvm (qemu hardware accelerated), qemu (qemu emulated), + # xen (Xen hypervisor), lxc (Linux Containers), + # esx (VMware ESX), vmwarews (VMware Workstation) and more. Refer to + # documentation for available drivers (http://libvirt.org/drivers.html). + libvirt.driver = "kvm" + + # The name of the server, where libvirtd is running. + # libvirt.host = "localhost" + + # If use ssh tunnel to connect to Libvirt. + libvirt.connect_via_ssh = false + + # The username and password to access Libvirt. Password is not used when + # connecting via ssh. + libvirt.username = "root" + #libvirt.password = "secret" + + # Libvirt storage pool name, where box image and instance snapshots will + # be stored. + libvirt.storage_pool_name = "default" + + # Set a prefix for the machines that's different than the project dir name. + #libvirt.default_prefix = '' + end +end \ No newline at end of file