summaryrefslogtreecommitdiff
path: root/packer/winserver2019.json
blob: b02c063bc7d59613a7df80b6eaa18622da1d0e9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
  "variables": {
    "iso_url": "https://software-static.download.prss.microsoft.com/pr/download/17763.737.190906-2324.rs5_release_svc_refresh_SERVER_EVAL_x64FRE_en-us_1.iso",
    "iso_path": "{{pwd}}/iso/17763.737.190906-2324.rs5_release_svc_refresh_SERVER_EVAL_x64FRE_en-us_1.iso",
    "iso_sha256": "sha256:549bca46c055157291be6c22a3aaaed8330e78ef4382c99ee82c896426a1cee1",
    "timestamp": "{{isotime `2006-01-02`}}",
    "headless": "false",
    "boot_wait": "2s",

    "name": "winserver2019",
    "cpu": "2",
    "cores": "2",
    "ram": "4096",
    "disk_size": "102400",
    "communicator_username": "packer",
    "communicator_password": "packer"
  },

  "builders": [
    {
      "type": "qemu",
      "format": "qcow2",
      "accelerator": "kvm",
      "net_device": "e1000",
      "disk_interface": "virtio",
      "headless": "{{user `headless`}}",
      "name": "qemu",
      "vm_name": "qemu-{{user `name`}}_{{user `timestamp`}}",
      "disk_size": "{{user `disk_size`}}",
      "disk_cache": "none",
      "disk_discard": "unmap",
      "disk_compression": true,
      "communicator": "winrm",
      "winrm_username": "{{user `communicator_username`}}",
      "winrm_password": "{{user `communicator_password`}}",
      "winrm_timeout": "99h",
      "shutdown_command": "C:\\sysprep-shutdown.bat",
      "boot_wait": "2s",
      "boot_command": ["<spacebar>", "<spacebar>", "<spacebar>", "<spacebar>", "<spacebar>", "<wait>", "<wait>", "<enter>"],
      "iso_urls": [
        "{{user `iso_path`}}",
        "{{user `iso_url`}}"
      ],
      "cd_files": [
        "files/drivers",
        "files/answer_files/windows/2019/autounattend.xml",
        "files/answer_files/windows/sysprep/sysprep.xml",
        "files/scripts/windows/enable-winrm-http.ps1"
      ],
      "iso_checksum": "{{user `iso_sha256`}}",
      "iso_target_path": "{{user `iso_path`}}",
      "output_directory": "qemu_output_{{user `name`}}",
      "qemuargs": [
        ["-m", "{{user `ram`}}M"],
        ["-cpu", "host"],
        ["-smp", "cpus={{user `cpu`}}"]
      ]
    }
  ],

  "provisioners": [
    {
      "type": "powershell",
      "elevated_user": "{{user `communicator_username`}}",
      "elevated_password": "{{user `communicator_password`}}",
      "pause_before": "30s",
      "script": "files/scripts/windows/init.ps1"
    },
    {
      "type": "file",
      "source": "files/scripts/windows/sysprep-shutdown.bat",
      "destination": "C:\\sysprep-shutdown.bat"
    },
    {
      "type": "powershell",
      "elevated_user": "Administrator",
      "elevated_password": "{{user `communicator_password`}}",
      "pause_before": "30s",
      "valid_exit_codes": ["3010", "1168"],
      "inline": [
        "DISM /Online /Set-edition:ServerStandard /ProductKey:N69G4-B89J2-4G8F4-WWYCC-J464C /AcceptEula /NoRestart /Quiet"
      ]
    },
    {
      "type": "windows-restart",
      "restart_timeout": "30m",
      "restart_command": "shutdown /r /f /t 0 /c \"packer restart\"",
      "restart_check_command": "powershell -command \"& {Write-Output 'restarted.'}\""
    },
    {
      "type": "powershell",
      "only": ["qemu"],
      "elevated_user": "{{user `communicator_username`}}",
      "elevated_password": "{{user `communicator_password`}}",
      "pause_before": "30s",
      "script": "files/scripts/windows/setup-qemu-guest-agent.ps1"
    },
    {
      "type": "windows-restart",
      "restart_timeout": "30m",
      "restart_command": "shutdown /r /f /t 0 /c \"packer restart\"",
      "restart_check_command": "powershell -command \"& {Write-Output 'restarted.'}\""
    },
    {
      "type": "powershell",
      "elevated_user": "{{user `communicator_username`}}",
      "elevated_password": "{{user `communicator_password`}}",
      "pause_before": "30s",
      "script": "files/scripts/windows/cleanup.ps1"
    },
    {
      "type": "windows-restart",
      "restart_timeout": "30m",
      "restart_command": "shutdown /r /f /t 0 /c \"packer restart\"",
      "restart_check_command": "powershell -command \"& {Write-Output 'restarted.'}\""
    }
  ],

  "post-processors": [
    {
      "type": "shell-local",
      "only_on": ["linux"],
      "environment_vars": [
        "NAME={{user `name`}}",
        "TIMESTAMP={{user `timestamp`}}"
      ],
      "script": "files/scripts/create-checksums.sh"
    }
  ]
}