├── .gitignore ├── README.md ├── alpine-3-amd64-proxmox ├── LICENSE ├── README.md ├── alpine-3-amd64-proxmox.json ├── build.conf ├── http │ └── answers ├── notes.md └── playbook │ ├── ansible.cfg │ ├── requirements.yml │ ├── server-template-vars.yml │ └── server-template.yml ├── alpine-3-amd64-qemu ├── LICENSE ├── README.md ├── alpine-3-amd64-qemu.json ├── alpine_id_rsa ├── alpine_id_rsa.ppk ├── alpine_id_rsa.pub ├── http │ └── answers ├── meta-data ├── notes-commands.md ├── output │ ├── cloud-data.iso │ └── qemu_4.2.0-1_amd64.deb ├── scripts │ ├── 00base.sh │ ├── 01alpine.sh │ ├── 01networking.sh │ ├── 02sshd.sh │ ├── 04sudoers.sh │ ├── 70random.sh │ ├── 80cloudinit.sh │ ├── 90showip.sh │ └── 99minimize.sh └── user-data ├── build.sh ├── check-functionality.md ├── debian-10-amd64-proxmox ├── README.md ├── build.conf ├── debian-10-amd64-proxmox.json ├── debug │ └── debian-10.0-x86_64-proxmox(parts).json ├── playbook │ ├── ansible.cfg │ ├── requirements.yml │ ├── server-template-vars.yml │ └── server-template.yml └── preseed.cfg.j2 ├── openbsd-6-amd64-proxmox ├── README.md ├── build.conf ├── debug │ └── filesets.sh ├── install.conf.j2 ├── install.conf.j2.test ├── openbsd-6-amd64-proxmox.json └── playbook │ ├── ansible.cfg │ ├── hosts │ ├── requirements.yml │ ├── server-template-vars.yml │ └── server-template.yml ├── ubuntu-18.04-amd64-proxmox ├── README.md ├── build.conf ├── debug │ └── packer-ansible.sh ├── playbook │ ├── ansible.cfg │ ├── requirements.yml │ ├── server-template-vars.yml │ └── server-template.yml ├── preseed.cfg.j2 └── ubuntu-18.04-amd64-proxmox.json └── ubuntu-20.04-amd64-proxmox ├── README.md ├── build.conf ├── playbook ├── ansible.cfg ├── requirements.yml ├── server-template-vars.yml └── server-template.yml ├── preseed.cfg.j2 └── ubuntu-20.04-amd64-proxmox.json /.gitignore: -------------------------------------------------------------------------------- 1 | *.img 2 | *.qcow2 3 | *.bz2 4 | *.zip 5 | *.bak 6 | *.bak2 7 | *.log 8 | *.log.* 9 | .DS_Store 10 | 11 | # ignore directories 12 | test/ 13 | roles/ 14 | crash_logs/ 15 | logs/ 16 | debug/ 17 | releases/ 18 | 19 | # ignore packer_cache 20 | packer_cache 21 | output-qemu 22 | packer-qemu 23 | 24 | # created from template 25 | preseed.cfg 26 | install.conf 27 | 28 | # others 29 | cloud-config.yml 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # packer-proxmox-templates 2 | :package: Packer templates for building Proxmox KVM images from ISO 3 | 4 | - use the latest tagged version which has been tested more thoroughly than 'master' 5 | 6 | #### [Debian ](https://www.debian.org/releases/) v10 (buster) [Packer Template](https://github.com/chriswayg/packer-proxmox-templates/tree/master/debian-10-amd64-proxmox) using Packer Proxmox Builder to build a Proxmox VM image template 7 | 8 | #### [Ubuntu ](http://releases.ubuntu.com/) 18.04 (bionic) [Packer Template](https://github.com/chriswayg/packer-proxmox-templates/tree/master/ubuntu-18.04-amd64-proxmox) using Packer Proxmox Builder to build a Proxmox VM image template 9 | 10 | #### [Ubuntu ](http://releases.ubuntu.com/) 20.04 (focal) [Packer Template](https://github.com/chriswayg/packer-proxmox-templates/tree/master/ubuntu-20.04-amd64-proxmox) using Packer Proxmox Builder to build a Proxmox VM image template 11 | 12 | #### [OpenBSD ](https://www.openbsd.org/index.html) 6 [Packer Template](https://github.com/chriswayg/packer-proxmox-templates/tree/master/openbsd-6-amd64-proxmox) using Packer Proxmox Builder to build a Proxmox VM image template 13 | 14 | #### [Alpine](https://wiki.alpinelinux.org/wiki/Alpine_Linux:Releases) Linux [Packer Template](https://github.com/chriswayg/packer-proxmox-templates/tree/master/alpine-3-amd64-proxmox) using Packer Proxmox Builder to build a Proxmox VM image template 15 | 16 | #### [Alpine](https://wiki.alpinelinux.org/wiki/Alpine_Linux:Releases) Linux [Packer Template](https://github.com/chriswayg/packer-proxmox-templates/tree/master/alpine-3-amd64-qemu) using QEMU Builder to build a KVM image usable in Openstack or Proxmox 17 | 18 | ## Proxmox KVM image templates 19 | 20 | - downloads the ISO and places it in Proxmox 21 | - creates a Proxmox VM 22 | - builds the image with Packer using automated installs 23 | - configures the image with Packer using Ansible 24 | - stores it as a Proxmox Template 25 | - see specific README.md for details about each template 26 | 27 | ### Check Prerequisites 28 | 29 | The build script which will run the packer template is *configured to run on the Proxmox server*. Thus the following pre-requisites should be installed on the Proxmox server: 30 | 31 | - Ensure that [Proxmox 6](https://www.proxmox.com/en/downloads) is installed 32 | - Set up a DHCP server on `vmbr1`, for example `isc-dhcp-server` (see section [DHCP](https://github.com/chriswayg/ansible-proxmox/blob/master/tasks/main.yml) in the Proxmox Ansible role). 33 | 34 | ``` 35 | printf "Proxmox $(pveversion)\n" 36 | ``` 37 | 38 | - Install [Packer](https://www.packer.io/downloads.html) on the Proxmox server 39 | 40 | ``` 41 | apt -y install unzip 42 | packer_ver=1.5.5 43 | wget https://releases.hashicorp.com/packer/${packer_ver}/packer_${packer_ver}_linux_amd64.zip 44 | sudo unzip packer_${packer_ver}_linux_amd64.zip -d /usr/local/bin 45 | packer --version 46 | ``` 47 | 48 | - Install [Ansible](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) on the Proxmox server 49 | 50 | ``` 51 | apt -y install python3-pip 52 | pip3 install ansible==2.9.7 53 | pip3 install py-bcrypt 54 | ``` 55 | 56 | - Install [j2cli](https://github.com/kolypto/j2cli) on the Proxmox server 57 | 58 | ``` 59 | pip3 install j2cli[yaml] 60 | ``` 61 | 62 | ### Download the latest tagged release of packer-proxmox-templates onto the Proxmox server 63 | 64 | `wget https://github.com/chriswayg/packer-proxmox-templates/archive/v1.7.zip && unzip v1.7.zip && cd packer-proxmox-templates-*` 65 | 66 | ### Usage 67 | 68 | On the Proxmox Server with Packer installed: 69 | 70 | ``` 71 | cd OSname-xy-amd64-proxmox 72 | 73 | # for example 74 | cd debian-10-amd64-proxmox 75 | cd ubuntu-18.04-amd64-proxmox 76 | cd openbsd-6-amd64-proxmox 77 | 78 | ``` 79 | 80 | - edit `build.conf`, including the default user and especially the Proxmox URL and the ISO download links for the latest distro version 81 | - edit `playbook/server-template-vars.yml`, especially the SSH Key & regional repositories 82 | 83 | ```sh 84 | ../build.sh proxmox 85 | ``` 86 | 87 | - The template creation can be observed in the Proxmox GUI 88 | - Login via SSH using the default username as set in `build.conf`, or login as root via console (if not disabled) 89 | 90 | ### Build Options 91 | 92 | ```sh 93 | ../build.sh (proxmox|debug [new_VM_ID]) 94 | 95 | proxmox - Build and create a Proxmox VM template 96 | debug - Debug Mode: Build and create a Proxmox VM template 97 | 98 | VM_ID - VM ID for new VM template (or use default from build.conf) 99 | 100 | Enter Passwords when prompted or provide them via ENV variables: 101 | (use a space in front of ' export' to keep passwords out of bash_history) 102 | export proxmox_password=MyLoginPassword 103 | export ssh_password=MyPasswordInVM 104 | ``` 105 | 106 | #### Build environment 107 | 108 | The Packer templates have been tested with the following versions of Packer and Ansible. If you use different versions, some details may need to be updated. 109 | 110 | ```sh 111 | printf "$(lsb_release -d) $(cat /etc/debian_version)\n" && \ 112 | printf "Proxmox $(pveversion)\n" && 113 | packer version && \ 114 | ansible --version | sed -n '1p' && \ 115 | ansible --version | sed -n '6p' && \ 116 | j2 --version 117 | 118 | Description: Debian GNU/Linux 10 (buster) 10.3 119 | Proxmox pve-manager/6.1-8/806edfe1 (running kernel: 5.3.18-3-pve) 120 | Packer v1.5.5 121 | ansible 2.9.7 122 | python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] 123 | j2cli 0.3.10, Jinja2 2.11.2 124 | ``` 125 | 126 | **NOTE:** For security reasons it would be preferable to build the Proxmox template images on a local Proxmox staging server (for example in a VM) and then to transfer the Proxmox templates using migration onto the live server(s). 127 | 128 | It should also be possible to use Packer remotely and to control VM creation remotely via Ansible. The Packer template and the scripts would have to be modified accordingly. If you have it working remotely, please make a pull request. 129 | -------------------------------------------------------------------------------- /alpine-3-amd64-proxmox/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /alpine-3-amd64-proxmox/README.md: -------------------------------------------------------------------------------- 1 | ## [Alpine Linux](http://alpinelinux.org) Packer Template using [Packer Proxmox Builder](https://www.packer.io/docs/builders/proxmox.html) to build a Proxmox KVM image template 2 | 3 | Status: **working** 4 | 5 | ### Features 6 | - downloads the ISO and places it in Proxmox 7 | - creates a Proxmox VM 8 | - builds the image using an answers file and bash scripts 9 | - stores it as a Proxmox Template 10 | 11 | ### Configurations 12 | - passwordless sudo for default user 'christian' 13 | - SSH public key installed for default user 14 | - display IP and SSH fingerprint before console login 15 | - automatically grow partition after resize by Proxmox 16 | 17 | ### Instructions 18 | - [REAMDE with Prerequisites and Usage](https://github.com/chriswayg/packer-proxmox-templates/blob/master/README.md) 19 | 20 | ### Docs 21 | - [Semi-Automatic Installation - Alpine Linux Documentation](https://beta.docs.alpinelinux.org/user-handbook/0.1a/Installing/manual.html) 22 | 23 | 24 | ### License and Credits 25 | - Apache 2.0 Copyright 2019 Christian Wagner 26 | - partially based on Matt Maier's [Packer Alpine Templates](https://github.com/maier/packer-templates) 27 | -------------------------------------------------------------------------------- /alpine-3-amd64-proxmox/alpine-3-amd64-proxmox.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Build Alpine Linux 3 x86_64 Proxmox template", 3 | "variables": { 4 | "proxmox_url": "{{env `proxmox_url`}}", 5 | "proxmox_username": "root@pam", 6 | "proxmox_password": "{{env `proxmox_password`}}", 7 | "proxmox_host": "{{env `proxmox_host`}}", 8 | "iso_filename": "{{env `iso_filename`}}", 9 | "vm_id": "{{env `vm_id`}}", 10 | "vm_name": "alpine3-tmpl", 11 | "template_description": "Alpine Linux 3.11 x86_64 template built with packer ({{env `vm_ver`}}). Username: {{env `vm_default_user`}}", 12 | "vm_default_user": "{{env `vm_default_user`}}", 13 | "vm_memory": "{{env `vm_memory`}}", 14 | "ssh_username": "root", 15 | "ssh_password": "{{env `ssh_password`}}" 16 | }, 17 | "sensitive-variables": ["proxmox_password", "ssh_password" ], 18 | "provisioners": [ 19 | { 20 | "type": "ansible", 21 | "playbook_file": "./playbook/server-template.yml", 22 | "extra_arguments": [ 23 | "{{user `ansible_verbosity`}}", 24 | "--extra-vars", "vm_default_user={{user `vm_default_user`}}", 25 | "--tags", "all,is_template", 26 | "--skip-tags", "debuntu,openbsd" 27 | ], 28 | "ansible_env_vars": [ "ANSIBLE_CONFIG=./playbook/ansible.cfg", "ANSIBLE_FORCE_COLOR=True" ] 29 | } 30 | ], 31 | "builders": [ 32 | { 33 | "type": "proxmox", 34 | "proxmox_url": "{{user `proxmox_url`}}", 35 | "insecure_skip_tls_verify": true, 36 | "username": "{{user `proxmox_username`}}", 37 | "password": "{{user `proxmox_password`}}", 38 | "vm_id": "{{user `vm_id`}}", 39 | "vm_name": "{{user `vm_name`}}", 40 | "template_description":"{{user `template_description`}}", 41 | "memory": "{{user `vm_memory`}}", 42 | "cores": "2", 43 | "os": "l26", 44 | "http_directory": "http", 45 | 46 | "node": "{{user `proxmox_host`}}", 47 | "network_adapters": [ 48 | { 49 | "model": "virtio", 50 | "bridge": "vmbr1" 51 | } 52 | ], 53 | "disks": [ 54 | { 55 | "type": "sata", 56 | "disk_size": "8G", 57 | "storage_pool": "local", 58 | "storage_pool_type": "directory", 59 | "format": "qcow2" 60 | } 61 | ], 62 | "ssh_username": "{{user `ssh_username`}}", 63 | "ssh_password": "{{user `ssh_password`}}", 64 | "ssh_timeout": "15m", 65 | "iso_file": "local:iso/{{user `iso_filename`}}", 66 | "unmount_iso": true, 67 | "boot_wait": "10s", 68 | "boot_command": [ 69 | "root", 70 | "ifconfig eth0 up && udhcpc -i eth0", 71 | "wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/answers", 72 | "setup-alpine -f $PWD/answers", 73 | "{{user `ssh_password`}}", 74 | "{{user `ssh_password`}}", 75 | "", 76 | "y", 77 | "", 78 | "rc-service sshd stop ", 79 | "mount /dev/sda2 /mnt ", 80 | "mount /dev/ /mnt/dev/ --bind ", 81 | "mount -t proc none /mnt/proc ", 82 | "mount -o bind /sys /mnt/sys ", 83 | "chroot /mnt /bin/sh -l ", 84 | "echo '@edgecommunity http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories ", 85 | "echo -e 'nameserver 1.1.1.1' > /etc/resolv.conf ", 86 | "apk update ", 87 | "apk add 'qemu-guest-agent@edgecommunity' 'python' ", 88 | "echo -e GA_PATH=\"/dev/vport1p1\" >> /etc/conf.d/qemu-guest-agent ", 89 | "rc-update add qemu-guest-agent ", 90 | "echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config ", 91 | "exit ", 92 | "umount /mnt/sys ", 93 | "umount /mnt/proc ", 94 | "umount /mnt/dev ", 95 | "umount /mnt ", 96 | "reboot " 97 | ] 98 | } 99 | ], 100 | "post-processors": [ 101 | { 102 | "type": "shell-local", 103 | "inline_shebang": "/bin/bash -e", 104 | "inline": ["qm set {{user `vm_id`}} --scsihw virtio-scsi-pci --serial0 socket --vga serial0"] 105 | } 106 | ] 107 | } 108 | -------------------------------------------------------------------------------- /alpine-3-amd64-proxmox/build.conf: -------------------------------------------------------------------------------- 1 | vm_default_user=christian 2 | vm_memory=1024 3 | default_vm_id=40000 # default VM ID for Alpine 4 | proxmox_url=https://proxmox.lightinasia.site:8006/api2/json 5 | proxmox_host=proxmox 6 | 7 | iso_url=http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-virt-3.11.6-x86_64.iso 8 | iso_sha256_url=http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-virt-3.11.6-x86_64.iso.sha256 9 | 10 | iso_directory=/var/lib/vz/template/iso 11 | -------------------------------------------------------------------------------- /alpine-3-amd64-proxmox/http/answers: -------------------------------------------------------------------------------- 1 | KEYMAPOPTS="us us" 2 | HOSTNAMEOPTS="-n alpine3" 3 | INTERFACESOPTS="auto lo 4 | iface lo inet loopback 5 | 6 | auto eth0 7 | iface eth0 inet dhcp 8 | hostname alpine3 9 | " 10 | DNSOPTS="-d local -n 1.1.1.1 1.0.0.1" 11 | TIMEZONEOPTS="-z UTC" 12 | PROXYOPTS="none" 13 | APKREPOSOPTS="http://nl.alpinelinux.org/alpine/v3.11/main 14 | http://nl.alpinelinux.org/alpine/v3.11/community 15 | " 16 | SSHDOPTS="-c openssh" 17 | NTPOPTS="-c chrony" 18 | DISKOPTS="-s 0 -m sys /dev/sda" 19 | -------------------------------------------------------------------------------- /alpine-3-amd64-proxmox/notes.md: -------------------------------------------------------------------------------- 1 | # scratchpad 2 | 3 | 4 | ### Docker 5 | ``` 6 | apk add docker-engine@edgecommunity docker-openrc@edgecommunity docker-cli@edgecommunity docker@edgecommunity 7 | docker --version 8 | 9 | apk add py3-setuptools python3-dev libffi-dev openssl-dev gcc libc-dev make 10 | pip3 install --upgrade pip 11 | pip3 install docker-compose 12 | docker-compose --version 13 | ``` 14 | or 15 | 16 | ``` 17 | apk add docker-compose@edgecommunity 18 | docker-compose --version 19 | ``` 20 | 21 | ### boot command: 22 | `openntpd` missing (error) 23 | 24 | ### qemu guest 25 | 26 | ``` 27 | host:~# cat /etc/conf.d/qemu-guest-agent 28 | # Specifies the transport method used to communicate to QEMU on the host side 29 | # Default: virtio-serial 30 | #GA_METHOD="virtio-serial" 31 | 32 | # Specifies the device path for the communications back to QEMU on the host 33 | # Default: /dev/virtio-ports/org.qemu.guest_agent.0 34 | GA_PATH="/dev/vport1p1" 35 | ``` 36 | -------------------------------------------------------------------------------- /alpine-3-amd64-proxmox/playbook/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | deprecation_warnings = False 3 | host_key_checking = False 4 | callback_whitelist = timer, profile_roles 5 | stdout_callback = yaml 6 | roles_path = ./roles 7 | log_path = ./logs/server-template.log 8 | -------------------------------------------------------------------------------- /alpine-3-amd64-proxmox/playbook/requirements.yml: -------------------------------------------------------------------------------- 1 | - src: https://github.com/chriswayg/ansible-initial-server.git 2 | #version: v1.7 3 | -------------------------------------------------------------------------------- /alpine-3-amd64-proxmox/playbook/server-template-vars.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | iserver_hostname: alpine3-kvm 4 | iserver_sshkey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDK1zNq5zsVbbN/gLdYqxlb5CROsR1dBNBgRFzzCJUL3ncU2dDHLHWi0L/FafwWt6MQ7vePu7catLDegY2fs1QB0KYvy21fD3+9ONBs7KcFlmuyqjLJ9VAoLWW5Tv3I9eZNgpd9k6CvYphKa1Owq43ye+quQRI4J+2nb7Zhl2WTQ1N2WBwZbmf0ErTHwa+mC7frTRBYh6ddyXp9KRULH89y/6cVpL6uQyFzIr6yWowUbJ8lX3fA9e7RAxkG76X54sMa65oq3Bog04ylJ4n/xZCXO449BZjAZHcJuDcFLXrwIo52t+Q6gIEnXInTiii26/ZWbnzzheggjkpQ77tCg03t christian@Chris-GigaMac.local" 5 | 6 | iserver_alpine_repos: 7 | - 'http://nl.alpinelinux.org/alpine/v3.11/main' 8 | - 'http://nl.alpinelinux.org/alpine/v3.11/community' 9 | - '@edge http://nl.alpinelinux.org/alpine/edge/main' 10 | - '@testing http://nl.alpinelinux.org/alpine/edge/testing' 11 | - '@edgecommunity http://dl-cdn.alpinelinux.org/alpine/edge/community' 12 | -------------------------------------------------------------------------------- /alpine-3-amd64-proxmox/playbook/server-template.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Any remote_user defined in tasks will be ignored. 3 | # Packer will always connect with the user given in the json config for this provisioner. 4 | # https://www.packer.io/docs/provisioners/ansible.html 5 | 6 | # TODO: For unclear reasons, I could only get it to work with the root user in Packer 7 | # 'become' in playbook or role tasks seem to be ignored by Packer Ansible 8 | 9 | - name: Initial configuration of a server. 10 | hosts: all 11 | vars_files: 12 | - server-template-vars.yml 13 | roles: 14 | - role: ansible-initial-server 15 | vars: 16 | iserver_user: "{{ vm_default_user }}" 17 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/README.md: -------------------------------------------------------------------------------- 1 | ## [Alpine Linux](http://alpinelinux.org) Packer Template using QEMU Builder to build a KVM cloud image usable in Proxmox or Openstack 2 | 3 | Status: **working** 4 | 5 | * this creates a cloud image with cloud-init to be used on Proxmox and possibly Openstack 6 | 7 | ### Prerequisites 8 | 9 | 1) Packer 1.5.5 requires a recent qemu version with gtk support and fails on Ubuntu 18.04. Therefore install a current qemu from source. 10 | 11 | - Install qemu build dependencies 12 | 13 | ``` 14 | sudo apt autoremove 15 | sudo apt purge qemu 16 | 17 | #sudo apt-get install build-essential pkg-config libglib2.0-dev libpixman-1-dev libgtk-3-dev 18 | sudo apt-get build-dep qemu 19 | sudo apt-get install libgtk-3-dev checkinstall 20 | ``` 21 | 22 | - Build and install qemu 4.2.0 23 | 24 | ``` 25 | wget https://download.qemu.org/qemu-4.2.0.tar.xz 26 | tar xvJf qemu-4.2.0 27 | cd qemu-4.2.0 28 | ./configure --target-list=x86_64-softmmu --enable-gtk 29 | make 30 | sudo checkinstall 31 | ``` 32 | 33 | 2) Install packer (see pre-reqs in main README) 34 | 35 | ### Usage notes 36 | 37 | ```sh 38 | cd alpine-3-amd64-qemu 39 | sudo packer build alpine-3-amd64-qemu.json 40 | ``` 41 | - The image is saved as `alpine-311-cloudimg-amd64.qcow2` in the `output` directory 42 | 43 | - Test the image locally: 44 | - adapt `user-data` and `meta-data` as needed 45 | - login as root on the console. Password: alpineqemu 46 | - login via ssh 47 | 48 | ```sh 49 | genisoimage -output output/cloud-data.iso -volid cidata -joliet -rock user-data meta-data 50 | 51 | sudo qemu-system-x86_64 output/alpine-311-cloudimg-amd64.qcow2 -netdev user,id=user.0,hostfwd=tcp::2222-:22 -device virtio-net,netdev=user.0 -cdrom output/cloud-data.iso 52 | 53 | ssh -i alpine_id_rsa -p 2222 alpine@localhost 54 | ``` 55 | - To install the image as a template on Proxmox, the following script can be used: 56 | - [Script to download a cloud image and create a Proxmox 6 template](https://gist.github.com/chriswayg/43fbea910e024cbe608d7dcb12cb8466) 57 | 58 | ### Features 59 | - default user alpine 60 | - add user-data via image drive 61 | - SSH login only via SHH key 62 | - passwordless sudo 63 | - no root login via ssh 64 | - optional root login via console 65 | 66 | ### cloud-init features on Alpine 67 | - the fuctionality is not quite complete on Alpine 68 | 69 | #### Working 70 | - getting user and metadata from image drive 71 | - setting hostname (1st boot) 72 | - setting up user (1st boot) 73 | - copying SSH authorized keys (1st boot) 74 | - automatically growing the disk drive with growpart 75 | - `qm resize 8000 scsi0 +30G` upon restart 76 | 77 | #### Not working (apparently) 78 | - writing of network config 79 | - password for user (not entered into `/etc/shadow`) 80 | - changed data on image-drive is not applied after 1st boot 81 | - serial console appears to be buggy, making it hard to log in 82 | 83 | ### Fulfills most Openstack requirements 84 | 85 | For a Linux-based image to have full functionality in an OpenStack Compute cloud, there are a few requirements. For some of these, you can fulfill the requirements by installing the [cloud-init](https://cloudinit.readthedocs.org/en/latest/) package. 86 | 87 | * Disk partitions and resize root partition on boot (cloud-init) 88 | * No hard-coded MAC address information 89 | * SSH server running 90 | * Disable firewall 91 | * Access instance using ssh public key (cloud-init) 92 | * Process user data and other metadata (cloud-init) 93 | 94 | [OpenStack Docs: Image requirements](https://docs.openstack.org/image-guide/openstack-images.html) 95 | 96 | ### Docs 97 | - [Semi-Automatic Installation - Alpine Linux Documentation](https://beta.docs.alpinelinux.org/user-handbook/0.1a/Installing/manual.html) 98 | - [OpenStack Docs: Create images manually](https://docs.openstack.org/image-guide/create-images-manually.html) 99 | 100 | ### Build environment 101 | 102 | ```sh 103 | packer version && qemu-system-x86_64 -version && lsb_release -d 104 | 105 | Packer v1.5.5 106 | QEMU emulator version 4.2.0 107 | Ubuntu 18.04.4 LTS 108 | ``` 109 | 110 | ### License and Credits 111 | - Apache 2.0 Copyright 2019 Christian Wagner 112 | - partially based on Matt Maier's [Packer Alpine Templates](https://github.com/maier/packer-templates) 113 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/alpine-3-amd64-qemu.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Build base Alpine Linux x86_64", 3 | 4 | "variables": { 5 | "disk_size": "2048", 6 | "memory": "1024", 7 | "cpus": "1" 8 | }, 9 | "provisioners": [ 10 | { 11 | "type": "shell", 12 | "scripts": [ 13 | "scripts/00base.sh", 14 | "scripts/01alpine.sh", 15 | "scripts/01networking.sh", 16 | "scripts/02sshd.sh", 17 | "scripts/04sudoers.sh", 18 | "scripts/70random.sh", 19 | "scripts/80cloudinit.sh", 20 | "scripts/90showip.sh", 21 | "scripts/99minimize.sh" 22 | ] 23 | } 24 | ], 25 | "builders": [ 26 | { 27 | "type": "qemu", 28 | "qemu_binary": "qemu-system-x86_64", 29 | "format": "qcow2", 30 | "accelerator": "kvm", 31 | "qemuargs": [ 32 | [ "-device", "virtio-rng-pci" ], 33 | [ "-device", "virtio-scsi-pci,id=scsi0" ], 34 | [ "-device", "scsi-hd,bus=scsi0.0,drive=drive0" ], 35 | [ "-device", "virtio-net,netdev=user.0" ] 36 | ], 37 | "disk_interface": "virtio-scsi", 38 | "headless": false, 39 | "disk_size": "{{user `disk_size`}}", 40 | "memory": "{{user `memory`}}", 41 | "cpus": "{{user `cpus`}}", 42 | "http_directory": "http", 43 | 44 | "iso_urls": ["isos/alpine-virt-3.11.5-x86_64.iso", 45 | "http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-virt-3.11.5-x86_64.iso"], 46 | "iso_checksum": "8e14a8f23d1d0a3772d486a94a7d707df65a942e605617ed6431fcb1ede387e4", 47 | "iso_checksum_type": "sha256", 48 | 49 | "communicator": "ssh", 50 | "ssh_username": "root", 51 | "ssh_password": "alpineqemu", 52 | "ssh_wait_timeout": "10m", 53 | "shutdown_command": "poweroff", 54 | "boot_wait": "30s", 55 | "boot_command": [ 56 | "root", 57 | "ifconfig eth0 up && udhcpc -i eth0", 58 | "wget http://{{ .HTTPIP }}:{{ .HTTPPort }}/answers", 59 | "setup-alpine -f $PWD/answers", 60 | "alpineqemu", 61 | "alpineqemu", 62 | "", 63 | "y", 64 | "", 65 | "", 66 | "rc-service sshd stop", 67 | "mount /dev/sda2 /mnt", 68 | "echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config", 69 | "umount /mnt", 70 | "reboot" 71 | ] 72 | } 73 | ], 74 | "post-processors": [ 75 | { 76 | "type": "shell-local", 77 | "inline": ["mv -fv output-qemu/packer-qemu output/alpine-311-cloudimg-amd64.qcow2 && rmdir -v output-qemu"] 78 | } 79 | ] 80 | } 81 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/alpine_id_rsa: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEArvZdvBLBAsidAnJ3ZKtNb2pFigEzr+P9KArOVV5futoZFWpI 3 | Ho74XJ1E7bith29MQpsovWuUGiBqoGKDIFXxarpGQjs0NcTeO+gPjM3bYLnQrdh5 4 | 3V8n5iU8HoE27OHUj/+jtt3Ofe1spu7le6Vn5oRdOZEV/3ysK0YuNoXcHcJ2+1Ye 5 | YsOY7D7J8zVXYkT8UgaDJTUaaIg8YIGFI7Fx16zVY2V72qbG3AYzLCWi15CdFEvV 6 | O/S6lPOqrK1mHvznYt5jXiLnagyxQW95jeFO2Ux9GsFDQqB9cr9l/5ahGcdmYF8J 7 | KsCqvW8j0gb94RGn0P/tHv/tyokHUd23gIc6kQIDAQABAoIBAQCLysar/WP/oGBq 8 | 0yB367LMIWH8WOd+UrAzrSac6PGd7qJ6DNggqmTgQrwPIC5t9sw8r5IGfozvrxTi 9 | nrNcQ67HcpuuUXVuvKQ/wzOhcd0lVHHaZQtBh8TuSrPVP7Kt4+YdQ8j/1AsnbGsS 10 | me/7MfZpJTsDQtwLrQY28TT9VUjA8QuCdz/1XFAq7eEqoOvQVfC+ulj5YwDqueHr 11 | zC6ewZ4GFp7tpj66qYM0YR3jZXjqQCeqiFyxTbTxcErhlihcE499uIUoedb7GS4W 12 | dOlTvfmZdxCM8xitXTDWrnmF3P+woXowE0gl8EcPmGcN+gsNUYgwnGF1YZM4/8Cd 13 | 0g7hKHIBAoGBAOJEtySti50urzrXF5hQ8/p6Kos/0IVgqBUQ1tcOWUZ2Ln9uuhpU 14 | F+Esx3TQV2ET6MIh3DIGzqahcPMdaVuw5WwLxW5RBPZ+I6G2vgsXEfF2oQspiKH+ 15 | M49LFjK+XKIeTQpGc4/r8RDwlPsO5K3HsezCdfCDJPN0r0sIL0V515qhAoGBAMXz 16 | zW7al+blz66XmI85H5qem/Vz8KioBNtLZK2SAazdtrDKhB7wR9ADKs4eOkWUOkeY 17 | e/Oh6AV0a9cPSZ/KiYiGO1Y/manZ51MAUjmlRepMJKCbckNAJLgzfFuXg5EtqYY7 18 | Q9mcPxae3U313H0hI77mGEd9NhcaoD0LlWaavwnxAoGBANsY9s6JTbuyTPOI+8v9 19 | 94H/cdrMvDmq0pczaxVrS38zSOsUaRi9fTIJjknKxBG4mZYB+5plhQ1NHnYLcM3c 20 | iQsKiu67fTbCBfa9YWCTwkgyOtb4LNnPsFV8u83/Duvcs3TTq2sdaJyimWBRl5W+ 21 | 3McJtfJiyxEDWAorrrpztRaBAoGAIW79KpT3BQOZoTZviPkv8lCJrNpJMmM2dsd0 22 | GLDJYaYM3i1GRWd16ZcvWqLWWrwfX8pMXSjiZFF2iVtGpxtxQULSsM2LKZnpLSan 23 | vJ7CgUEdCpdWpC8oRIhFn76mdRXORSKrYgy2xx5L6If3FpdLT0nTnfdy9FIF8GmN 24 | cUf/rjECgYBfGI7fUm6E98xuuQGDOMiP4VPGm4aOznCnyXF3fI+Uw0ke/kI+Wvm+ 25 | LEeEHGlbOiS7x8nV5usm9j1DDrOFBhMWIC9Rasn6NZbcMYoQpiYABPJHBBGaqa19 26 | PX9Dt8IssWUIhX1fFQdTJrzMo1VPZMu5NR3Axfp+z3ubosrTuplS1A== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/alpine_id_rsa.ppk: -------------------------------------------------------------------------------- 1 | PuTTY-User-Key-File-2: ssh-rsa 2 | Encryption: none 3 | Comment: imported-openssh-key 4 | Public-Lines: 6 5 | AAAAB3NzaC1yc2EAAAADAQABAAABAQCu9l28EsECyJ0Ccndkq01vakWKATOv4/0o 6 | Cs5VXl+62hkVakgejvhcnUTtuK2Hb0xCmyi9a5QaIGqgYoMgVfFqukZCOzQ1xN47 7 | 6A+MzdtgudCt2HndXyfmJTwegTbs4dSP/6O23c597Wym7uV7pWfmhF05kRX/fKwr 8 | Ri42hdwdwnb7Vh5iw5jsPsnzNVdiRPxSBoMlNRpoiDxggYUjsXHXrNVjZXvapsbc 9 | BjMsJaLXkJ0US9U79LqU86qsrWYe/Odi3mNeIudqDLFBb3mN4U7ZTH0awUNCoH1y 10 | v2X/lqEZx2ZgXwkqwKq9byPSBv3hEafQ/+0e/+3KiQdR3beAhzqR 11 | Private-Lines: 14 12 | AAABAQCLysar/WP/oGBq0yB367LMIWH8WOd+UrAzrSac6PGd7qJ6DNggqmTgQrwP 13 | IC5t9sw8r5IGfozvrxTinrNcQ67HcpuuUXVuvKQ/wzOhcd0lVHHaZQtBh8TuSrPV 14 | P7Kt4+YdQ8j/1AsnbGsSme/7MfZpJTsDQtwLrQY28TT9VUjA8QuCdz/1XFAq7eEq 15 | oOvQVfC+ulj5YwDqueHrzC6ewZ4GFp7tpj66qYM0YR3jZXjqQCeqiFyxTbTxcErh 16 | lihcE499uIUoedb7GS4WdOlTvfmZdxCM8xitXTDWrnmF3P+woXowE0gl8EcPmGcN 17 | +gsNUYgwnGF1YZM4/8Cd0g7hKHIBAAAAgQDiRLckrYudLq861xeYUPP6eiqLP9CF 18 | YKgVENbXDllGdi5/broaVBfhLMd00FdhE+jCIdwyBs6moXDzHWlbsOVsC8VuUQT2 19 | fiOhtr4LFxHxdqELKYih/jOPSxYyvlyiHk0KRnOP6/EQ8JT7DuStx7HswnXwgyTz 20 | dK9LCC9FedeaoQAAAIEAxfPNbtqX5uXPrpeYjzkfmp6b9XPwqKgE20tkrZIBrN22 21 | sMqEHvBH0AMqzh46RZQ6R5h786HoBXRr1w9Jn8qJiIY7Vj+ZqdnnUwBSOaVF6kwk 22 | oJtyQ0AkuDN8W5eDkS2phjtD2Zw/Fp7dTfXcfSEjvuYYR302FxqgPQuVZpq/CfEA 23 | AACAXxiO31JuhPfMbrkBgzjIj+FTxpuGjs5wp8lxd3yPlMNJHv5CPlr5vixHhBxp 24 | Wzoku8fJ1ebrJvY9Qw6zhQYTFiAvUWrJ+jWW3DGKEKYmAATyRwQRmqmtfT1/Q7fC 25 | LLFlCIV9XxUHUya8zKNVT2TLuTUdwMX6fs97m6LK07qZUtQ= 26 | Private-MAC: cc9bd253b5cab2859e8324323fa108e5308d8108 27 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/alpine_id_rsa.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCu9l28EsECyJ0Ccndkq01vakWKATOv4/0oCs5VXl+62hkVakgejvhcnUTtuK2Hb0xCmyi9a5QaIGqgYoMgVfFqukZCOzQ1xN476A+MzdtgudCt2HndXyfmJTwegTbs4dSP/6O23c597Wym7uV7pWfmhF05kRX/fKwrRi42hdwdwnb7Vh5iw5jsPsnzNVdiRPxSBoMlNRpoiDxggYUjsXHXrNVjZXvapsbcBjMsJaLXkJ0US9U79LqU86qsrWYe/Odi3mNeIudqDLFBb3mN4U7ZTH0awUNCoH1yv2X/lqEZx2ZgXwkqwKq9byPSBv3hEafQ/+0e/+3KiQdR3beAhzqR christian@ubuntu 2 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/http/answers: -------------------------------------------------------------------------------- 1 | KEYMAPOPTS="us us" 2 | HOSTNAMEOPTS="-n alpine3" 3 | INTERFACESOPTS="auto lo 4 | iface lo inet loopback 5 | 6 | auto eth0 7 | iface eth0 inet dhcp 8 | hostname alpine3 9 | " 10 | DNSOPTS="-d local -n 1.1.1.1 1.0.0.1" 11 | TIMEZONEOPTS="-z UTC" 12 | PROXYOPTS="none" 13 | APKREPOSOPTS="http://dl-cdn.alpinelinux.org/alpine/v3.11/main" 14 | SSHDOPTS="-c openssh" 15 | NTPOPTS="-c openntpd" 16 | DISKOPTS="-s 0 -m sys /dev/sda" 17 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/meta-data: -------------------------------------------------------------------------------- 1 | instance-id: 12fb410a-6652-46e9-8b32-db6698678ddc 2 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/notes-commands.md: -------------------------------------------------------------------------------- 1 | ## Misc. Notes 2 | 3 | - Alpine boot kernel 'virt' with randomness from CPU & info during boot for testing 4 | ``` 5 | virt random.trust_cpu=1 debug 6 | ``` 7 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/output/cloud-data.iso: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chriswayg/packer-proxmox-templates/fd588b25e698cf66cbb06a5a7b6f8bc71b9f0193/alpine-3-amd64-qemu/output/cloud-data.iso -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/output/qemu_4.2.0-1_amd64.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chriswayg/packer-proxmox-templates/fd588b25e698cf66cbb06a5a7b6f8bc71b9f0193/alpine-3-amd64-qemu/output/qemu_4.2.0-1_amd64.deb -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/scripts/00base.sh: -------------------------------------------------------------------------------- 1 | set -ux 2 | 3 | apk upgrade -U --available 4 | 5 | source /etc/os-release 6 | 7 | printf "\n $PRETTY_NAME ($VERSION_ID) Cloud Server\n\n" > /etc/motd 8 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/scripts/01alpine.sh: -------------------------------------------------------------------------------- 1 | set -ux 2 | 3 | # adding repositories needed for cloud-init 4 | echo "http://nl.alpinelinux.org/alpine/v3.11/community" >> /etc/apk/repositories 5 | echo "@edge http://nl.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories 6 | echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories 7 | echo "@edgecommunity http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories 8 | 9 | # update all packages, including the kernel. 10 | apk update 11 | apk upgrade 12 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/scripts/01networking.sh: -------------------------------------------------------------------------------- 1 | set -ux 2 | 3 | # nothing special required 4 | 5 | exit 0 -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/scripts/02sshd.sh: -------------------------------------------------------------------------------- 1 | set -eux 2 | 3 | # RootLogin without password was permitted in order to allow packer ssh access 4 | # to provision the system. Its removed here to make the server more secure. 5 | sed -i '/^PermitRootLogin no/d' /etc/ssh/sshd_config 6 | 7 | # disable ssh password authentication 8 | sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config 9 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/scripts/04sudoers.sh: -------------------------------------------------------------------------------- 1 | set -eux 2 | 3 | # this configuration allows the alpine account to sudo su - without needing a password 4 | 5 | # Install sudo 6 | apk add sudo shadow 7 | 8 | # Create Initial User 9 | adduser -D alpine -G wheel 10 | 11 | # allow sudo without password 12 | echo "Defaults exempt_group=wheel" > /etc/sudoers 13 | echo "%wheel ALL=NOPASSWD:ALL" >> /etc/sudoers 14 | 15 | # allows ssh login without the user being locked 16 | # https://unix.stackexchange.com/questions/193066/how-to-unlock-account-for-public-key-ssh-authorization-but-not-for-password-aut 17 | usermod -p '*' alpine 18 | 19 | # the root user is also being blocked from ssh login in sshd_config 20 | # remove root password (optional - makes it impossible to login as root from console) 21 | #usermod -p '*' root 22 | 23 | # lock root account 24 | #passwd -l root 25 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/scripts/70random.sh: -------------------------------------------------------------------------------- 1 | set -eux 2 | 3 | # Fixes: Boot delay/issues because of limited entropy 4 | # https://gitlab.alpinelinux.org/alpine/aports/issues/9960 5 | apk add haveged 6 | rc-update add haveged boot 7 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/scripts/80cloudinit.sh: -------------------------------------------------------------------------------- 1 | set -eux 2 | 3 | apk add cloud-init@testing 4 | 5 | # install missing dependencies 6 | apk add eudev 7 | 8 | # needed for 'growpart' 9 | apk add cloud-utils@testing 10 | 11 | # install utils 12 | apk add acpi 13 | apk add nano 14 | 15 | # make sure CD drive with cloud-init config data gets mounted 16 | # /dev/sr0 /media/cdrom iso9660 ro 0 0 17 | sed -i 's/\/dev\/cdrom/\/dev\/sr0/g' /etc/fstab 18 | sed -i 's/noauto,ro/ro/g' /etc/fstab 19 | 20 | # writing of network config is not implemented in alpine cloud-init 21 | #apk add iproute2 ifupdown 22 | echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg 23 | 24 | # Start Cloud-Init on Boot 25 | rc-update add cloud-init default 26 | 27 | # enable automatically growing the partition 28 | cat > /etc/cloud/cloud.cfg.d/10_growpart.cfg << "EOF" 29 | growpart: 30 | mode: growpart 31 | devices: ["/dev/sda2"] 32 | ignore_growroot_disabled: false 33 | 34 | # the above settings do not seem to get used, thus run growpart here 35 | bootcmd: 36 | - growpart /dev/sda 2 37 | EOF 38 | 39 | # activate serial console 40 | # it is buggy, as it makes it hard to log in 41 | 42 | # sed -i 's/quiet/console=ttyS0,9600/g' /etc/update-extlinux.conf 43 | # update-extlinux 44 | # 45 | # sed -i 's/#ttyS0/ttyS0/g' /etc/inittab 46 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/scripts/90showip.sh: -------------------------------------------------------------------------------- 1 | # show SSH key fingerprint and IP address on console 2 | 3 | cp /etc/issue /etc/issue-standard 4 | 5 | # Creates a script which will run when the network comes up 6 | cat > /etc/network/if-up.d/show-ip-address << "EOF" 7 | #!/bin/sh 8 | if [ "$METHOD" = loopback ]; then 9 | exit 0 10 | fi 11 | 12 | # Only run from ifup. 13 | if [ "$MODE" != start ]; then 14 | exit 0 15 | fi 16 | 17 | cp /etc/issue-standard /etc/issue 18 | printf "ECDSA key fingerprint:\n$(ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub)\n" >> /etc/issue 19 | printf "\nSSH user: alpine IP: $(ifconfig eth0 | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')\n\n" >> /etc/issue 20 | 21 | EOF 22 | 23 | chmod +x /etc/network/if-up.d/show-ip-address 24 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/scripts/99minimize.sh: -------------------------------------------------------------------------------- 1 | set -ux 2 | 3 | dd if=/dev/zero of=/EMPTY bs=1M 4 | rm -f /EMPTY 5 | # Block until the empty file has been removed, otherwise, Packer 6 | # will try to kill the box while the disk is still full and that's bad 7 | sync 8 | sync 9 | sync 10 | 11 | exit 0 12 | -------------------------------------------------------------------------------- /alpine-3-amd64-qemu/user-data: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | hostname: alpine3 3 | ssh_authorized_keys: 4 | - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCu9l28EsECyJ0Ccndkq01vakWKATOv4/0oCs5VXl+62hkVakgejvhcnUTtuK2Hb0xCmyi9a5QaIGqgYoMgVfFqukZCOzQ1xN476A+MzdtgudCt2HndXyfmJTwegTbs4dSP/6O23c597Wym7uV7pWfmhF05kRX/fKwrRi42hdwdwnb7Vh5iw5jsPsnzNVdiRPxSBoMlNRpoiDxggYUjsXHXrNVjZXvapsbcBjMsJaLXkJ0US9U79LqU86qsrWYe/Odi3mNeIudqDLFBb3mN4U7ZTH0awUNCoH1yv2X/lqEZx2ZgXwkqwKq9byPSBv3hEafQ/+0e/+3KiQdR3beAhzqR christian@ubuntu 5 | chpasswd: 6 | expire: False 7 | users: 8 | - default 9 | package_upgrade: true 10 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Many variables are sourced from build.conf and passed as environment variables to Packer. 4 | # The vm_default_user name will be used by Packer and Ansible. 5 | # (j2 is a better solution than 'envsubst' which messes up '$' in the text unless you specify each variable) 6 | # vm_default_user 7 | # vm_memory 8 | # proxmox_host 9 | # iso_filename 10 | # vm_ver 11 | # vm_id 12 | # proxmox_password 13 | # ssh_password 14 | 15 | set -o allexport 16 | build_conf="build.conf" 17 | 18 | function help { 19 | printf "\n" 20 | echo "$0 (proxmox|debug [VM_ID])" 21 | echo 22 | echo "proxmox - Build and create a Proxmox VM template" 23 | echo "debug - Debug Mode: Build and create a Proxmox VM template" 24 | echo 25 | echo "VM_ID - VM ID for new VM template (overrides default from build.conf)" 26 | echo 27 | echo "Enter Passwwords when prompted or provide them via ENV variables:" 28 | echo "(use a space in front of ' export' to keep passwords out of bash_history)" 29 | echo " export proxmox_password=MyLoginPassword" 30 | echo " export ssh_password=MyPasswordInVM" 31 | printf "\n" 32 | exit 0 33 | } 34 | 35 | function die_var_unset { 36 | echo "ERROR: Variable '$1' is required to be set. Please edit '${build_conf}' and set." 37 | exit 1 38 | } 39 | 40 | ## check that data in build_conf is complete 41 | [[ -f $build_conf ]] || { echo "User variables file '$build_conf' not found."; exit 1; } 42 | source $build_conf 43 | 44 | [[ -z "$vm_default_user" ]] && die_var_unset "vm_default_user" 45 | [[ -z "$vm_memory" ]] && die_var_unset "vm_memory" 46 | [[ -z "$proxmox_host" ]] && die_var_unset "proxmox_host" 47 | [[ -z "$default_vm_id" ]] && die_var_unset "default_vm_id" 48 | [[ -z "$iso_url" ]] && die_var_unset "iso_url" 49 | [[ -z "$iso_sha256_url" ]] && die_var_unset "iso_sha256_url" 50 | [[ -z "$iso_directory" ]] && die_var_unset "iso_directory" 51 | 52 | ## check that build-mode (proxmox|debug) is passed to script 53 | target=${1:-} 54 | [[ "${1}" == "proxmox" ]] || [[ "${1}" == "debug" ]] || help 55 | 56 | ## VM ID for new VM template (overrides default from build.conf) 57 | vm_id=${2:-$default_vm_id} 58 | printf "\n==> Using VM ID: $vm_id with default user: '$vm_default_user'\n" 59 | 60 | ## template_name is based on name of current directory, check it exists 61 | template_name="${PWD##*/}.json" 62 | 63 | [[ -f $template_name ]] || { echo "Template (${template_name}) not found."; exit 1; } 64 | 65 | ## check that prerequisites are installed 66 | [[ $(packer --version) ]] || { echo "Please install 'Packer'"; exit 1; } 67 | [[ $(ansible --version) ]] || { echo "Please install 'Ansible'"; exit 1; } 68 | [[ $(j2 --version) ]] || { echo "Please install 'j2cli'"; exit 1; } 69 | 70 | ## If passwords are not set in env variable, prompt for them 71 | [[ -z "$proxmox_password" ]] && printf "\n" && read -s -p "Existing PROXMOX Login Password: " proxmox_password && printf "\n" 72 | printf "\n" 73 | 74 | if [[ -z "$ssh_password" ]]; then 75 | while true; do 76 | read -s -p "Enter new SSH Password: " ssh_password 77 | printf "\n" 78 | read -s -p "Repeat new SSH Password: " ssh_password2 79 | printf "\n" 80 | [ "$ssh_password" = "$ssh_password2" ] && break 81 | printf "Passwords do not match. Please try again!\n\n" 82 | done 83 | fi 84 | 85 | [[ -z "$proxmox_password" ]] && echo "The Proxmox Password is required." && exit 1 86 | [[ -z "$ssh_password" ]] && echo "The SSH Password is required." && exit 1 87 | 88 | ## download ISO and Ansible role 89 | printf "\n=> Downloading and checking ISO\n\n" 90 | iso_filename=$(basename $iso_url) 91 | wget -P $iso_directory -N $iso_url # only re-download when newer on the server 92 | wget --no-verbose $iso_sha256_url -O $iso_directory/SHA256SUMS # always download and overwrite 93 | (cd $iso_directory && cat $iso_directory/SHA256SUMS | grep $iso_filename | sha256sum --check) 94 | if [ $? -eq 1 ]; then echo "ISO checksum does not match!"; exit 1; fi 95 | 96 | printf "\n=> Downloading Ansible role\n\n" 97 | # will always overwrite role to get latest version from Github 98 | ansible-galaxy install --force -p playbook/roles -r playbook/requirements.yml 99 | [[ -f playbook/roles/ansible-initial-server/tasks/main.yml ]] || { echo "Ansible role not found."; exit 1; } 100 | 101 | mkdir -p http 102 | 103 | # Debian & Ubuntu 104 | ## Insert the password hashes for root and default user into preseed.cfg using a Jinja2 template 105 | if [[ -f preseed.cfg.j2 ]]; then 106 | password_hash1=$(mkpasswd -R 1000000 -m sha-512 $ssh_password) 107 | password_hash2=$(mkpasswd -R 1000000 -m sha-512 $ssh_password) 108 | printf "\n=> Customizing auto preseed.cfg\n" 109 | j2 preseed.cfg.j2 > http/preseed.cfg 110 | [[ -f http/preseed.cfg ]] || { echo "Customized preseed.cfg file not found."; exit 1; } 111 | fi 112 | 113 | # OpenBSD 114 | ## Insert the password hashes for root and default user into install.conf using a Jinja2 template 115 | if [[ -f install.conf.j2 ]]; then 116 | password_hash1=$(python3 -c "import os, bcrypt; print(bcrypt.hashpw(os.environ['ssh_password'], bcrypt.gensalt(10)))") 117 | password_hash2=$(python3 -c "import os, bcrypt; print(bcrypt.hashpw(os.environ['ssh_password'], bcrypt.gensalt(10)))") 118 | printf "\n=> Customizing install.conf\n" 119 | j2 install.conf.j2 > http/install.conf 120 | [[ -f http/install.conf ]] || { echo "Customized install.conf file not found."; exit 1; } 121 | fi 122 | 123 | vm_ver=$(git describe --tags) 124 | 125 | 126 | ## Call Packer build with the provided data 127 | case $target in 128 | proxmox) 129 | printf "\n==> Build and create a Proxmox template.\n\n" 130 | ansible_verbosity="-v" 131 | packer build $template_name 132 | ;; 133 | debug) 134 | printf "\n==> DEBUG: Build and create a Proxmox template.\n\n" 135 | ansible_verbosity="-vvvv" 136 | PACKER_LOG=1 packer build -debug -on-error=ask $template_name 137 | ;; 138 | *) 139 | help 140 | ;; 141 | esac 142 | 143 | ## remove file which has the hashed passwords 144 | [[ -f http/preseed.cfg ]] && printf "=> " && rm -v http/preseed.cfg 145 | [[ -f http/install.conf ]] && printf "=> " && rm -v http/install.conf 146 | -------------------------------------------------------------------------------- /check-functionality.md: -------------------------------------------------------------------------------- 1 | # Check the functionality of features 2 | 3 | ### 4 | 5 | ### Check that services are enabled 6 | 7 | ``` 8 | # Debian/Ubuntu 9 | systemctl list-unit-files | grep -E 'autogrowpart|ssh-host-keygen' 10 | 11 | systemctl status ssh-host-keygen 12 | systemctl status autogrowpart 13 | pstree 14 | 15 | # Alpine 16 | rc-status | grep 'local ' 17 | pstree 18 | 19 | # OpenBSD 20 | rcctl ls on 21 | rcctl ls started 22 | pstree 23 | ``` 24 | 25 | 26 | ### Check that autogrow partition works (all OS) 27 | 28 | - check disk space 29 | ``` 30 | df -h 31 | poweroff 32 | ``` 33 | 34 | - increase disk size in Proxmox and check disk space again 35 | ``` 36 | df-h 37 | ``` 38 | 39 | ### Check ssh-host-keygen and fingerprint & IP display 40 | 41 | - create two clones in Proxmox 42 | - check fingerprints and IP before login on console 43 | 44 | 45 | ### 46 | - check ssh login 47 | 48 | `ssh -p 3XX22 christian@proxmox.lightinasia.site` 49 | 50 | ### Ansible Playbook 51 | 52 | - run the playbook again separately on a clone 53 | 54 | ### Default VM Numbers 55 | - 10000 Debian 8 56 | - 11000 Debian 9 57 | - 12000 Debian 10 58 | - 20000 Ubuntu 18.04 59 | - 21000 Ubuntu 20.04 60 | - 22000 Ubuntu 22.04 61 | - 31000 Centos 7 62 | - 40000 Alpine 3.11 63 | - 42000 Arch 64 | - 44000 RancherOS 1.5.5 65 | - 46000 CoreOS/Flatcar 66 | - 47000 OpenBSD 67 | 68 | ### Default [Cloud VM](https://gist.github.com/chriswayg/43fbea910e024cbe608d7dcb12cb8466) Numbers 69 | - 51000 Debian 8 70 | - 51100 Debian 9 71 | - 51200 Debian 10 72 | - 52000 Ubuntu 18.04 73 | - 52100 Ubuntu 20.04 74 | - 52200 Ubuntu 22.04 75 | - 53100 Centos 7 76 | - 54000 Alpine 3.11 77 | - 54200 Arch 78 | - 54400 RancherOS 1.5.5 79 | - 54600 CoreOS/Flatcar 80 | -------------------------------------------------------------------------------- /debian-10-amd64-proxmox/README.md: -------------------------------------------------------------------------------- 1 | ## [Debian ](http://debian.org) v10.0 (buster) Packer Template using [Packer Proxmox Builder](https://www.packer.io/docs/builders/proxmox.html) to build a Proxmox KVM image template 2 | 3 | Status: **working well** 4 | 5 | - downloads the ISO and places it in Proxmox 6 | - creates a Proxmox VM 7 | - builds the image using preseed.cfg and Ansible 8 | - stores it as a Proxmox Template 9 | 10 | ### Configurations 11 | - qemu-guest-agent for Packer SSH and in Proxmox for shutdown and backups 12 | - haveged random number generator to speed up boot 13 | - passwordless sudo for default user 'deploy' (name can be changed in build.conf) 14 | - SSH public key installed for default user 15 | - display IP and SSH fingerprint before console login 16 | - generates new SSH host keys on first boot to avoid duplicates in cloned VMs 17 | - automatically grow partition after resize by Proxmox 18 | 19 | ### Instructions 20 | 21 | - [REAMDE with Prerequisites and Usage](https://github.com/chriswayg/packer-proxmox-templates/blob/master/README.md) 22 | -------------------------------------------------------------------------------- /debian-10-amd64-proxmox/build.conf: -------------------------------------------------------------------------------- 1 | vm_default_user=christian 2 | vm_memory=1024 3 | default_vm_id=12000 # default VM ID for Debian 4 | proxmox_url=https://proxmox.lightinasia.site:8006/api2/json 5 | proxmox_host=proxmox 6 | 7 | # latest version: http://cdimage.debian.org/cdimage/release/current/amd64/iso-cd/ 8 | iso_url=http://cdimage.debian.org/cdimage/release/current/amd64/iso-cd/debian-10.4.0-amd64-netinst.iso 9 | iso_sha256_url=https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/SHA256SUMS 10 | iso_directory=/var/lib/vz/template/iso 11 | -------------------------------------------------------------------------------- /debian-10-amd64-proxmox/debian-10-amd64-proxmox.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Build Debian 10 (buster) x86_64 Proxmox template", 3 | "variables": { 4 | "proxmox_url": "{{env `proxmox_url`}}", 5 | "proxmox_username": "root@pam", 6 | "proxmox_password": "{{env `proxmox_password`}}", 7 | "proxmox_host": "{{env `proxmox_host`}}", 8 | "iso_filename": "{{env `iso_filename`}}", 9 | "vm_id": "{{env `vm_id`}}", 10 | "vm_name": "deb10-tmpl", 11 | "template_description": "Debian 10 x86_64 template built with packer ({{env `vm_ver`}}). Username: {{env `vm_default_user`}}", 12 | "vm_default_user": "{{env `vm_default_user`}}", 13 | "vm_memory": "{{env `vm_memory`}}", 14 | "ssh_username": "root", 15 | "ssh_password": "{{env `ssh_password`}}" 16 | }, 17 | "sensitive-variables": ["proxmox_password", "ssh_password" ], 18 | "provisioners": [ 19 | { 20 | "type": "ansible", 21 | "playbook_file": "./playbook/server-template.yml", 22 | "extra_arguments": [ 23 | "{{user `ansible_verbosity`}}", 24 | "--extra-vars", "vm_default_user={{user `vm_default_user`}}", 25 | "--tags", "all,is_template", 26 | "--skip-tags", "openbsd,alpine" 27 | ], 28 | "ansible_env_vars": [ "ANSIBLE_CONFIG=./playbook/ansible.cfg", "ANSIBLE_FORCE_COLOR=True" ] 29 | } 30 | ], 31 | "builders": [ 32 | { 33 | "type": "proxmox", 34 | "proxmox_url": "{{user `proxmox_url`}}", 35 | "insecure_skip_tls_verify": true, 36 | "username": "{{user `proxmox_username`}}", 37 | "password": "{{user `proxmox_password`}}", 38 | "vm_id": "{{user `vm_id`}}", 39 | "vm_name": "{{user `vm_name`}}", 40 | "template_description":"{{user `template_description`}}", 41 | "memory": "{{user `vm_memory`}}", 42 | "cores": "2", 43 | "os": "l26", 44 | "http_directory": "http", 45 | "node": "{{user `proxmox_host`}}", 46 | "network_adapters": [ 47 | { 48 | "model": "virtio", 49 | "bridge": "vmbr1" 50 | } 51 | ], 52 | "disks": [ 53 | { 54 | "type": "scsi", 55 | "disk_size": "8G", 56 | "storage_pool": "local", 57 | "storage_pool_type": "directory", 58 | "format": "qcow2" 59 | } 60 | ], 61 | "ssh_username": "{{user `ssh_username`}}", 62 | "ssh_password": "{{user `ssh_password`}}", 63 | "ssh_timeout": "15m", 64 | "iso_file": "local:iso/{{user `iso_filename`}}", 65 | "unmount_iso": true, 66 | "boot_wait": "10s", 67 | "boot_command": [ 68 | "", 69 | "auto url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg" 70 | ] 71 | } 72 | ], 73 | "post-processors": [ 74 | { 75 | "type": "shell-local", 76 | "inline_shebang": "/bin/bash -e", 77 | "inline": ["qm set {{user `vm_id`}} --scsihw virtio-scsi-pci --serial0 socket --vga serial0"] 78 | } 79 | ] 80 | } 81 | -------------------------------------------------------------------------------- /debian-10-amd64-proxmox/debug/debian-10.0-x86_64-proxmox(parts).json: -------------------------------------------------------------------------------- 1 | # when using the shell provisioner 2 | 3 | "provisioners": [ 4 | { 5 | "type": "shell", 6 | "execute_command": "echo '{{user `vm_default_user`}}' | sudo -S sh '{{.Path}}'", 7 | "scripts": [ 8 | "scripts/00base.sh", 9 | "scripts/01networking.sh", 10 | "scripts/02sshd.sh", 11 | "scripts/04sudoers.sh", 12 | "scripts/05customize.sh", 13 | "scripts/06cloud.sh", 14 | "scripts/90cleanup.sh", 15 | "scripts/99minimize.sh" 16 | ] 17 | } 18 | ], 19 | 20 | 21 | # when using the null builder 22 | 23 | "builders": [ 24 | { 25 | "type": "null", 26 | "ssh_host": "10.10.10.77", 27 | "ssh_username": "root", 28 | "ssh_password": "*****", 29 | "ssh_timeout": "1m" 30 | } 31 | ] 32 | 33 | 34 | # the original boot boot_command (auto is much faster) 35 | 36 | "boot_command": [ 37 | "", 38 | "install", 39 | " url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", 40 | " debian-installer=en_US", 41 | " auto locale=en_US.UTF-8", 42 | " kbd-chooser/method=us", 43 | " keyboard-configuration/xkb-keymap=us", 44 | " netcfg/get_hostname={{user `vm_hostname`}}", 45 | " netcfg/get_domain=unassigned.domain", 46 | " fb=false", 47 | " debconf/frontend=noninteractive", 48 | " console-setup/ask_detect=false", 49 | " console-setup/charmap47=UTF-8", 50 | " console-keymaps-at/keymap=us", 51 | "" 52 | ] 53 | -------------------------------------------------------------------------------- /debian-10-amd64-proxmox/playbook/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | deprecation_warnings = False 3 | host_key_checking = False 4 | callback_whitelist = timer, profile_roles 5 | stdout_callback = yaml 6 | roles_path = ./roles 7 | log_path = ./logs/server-template.log 8 | -------------------------------------------------------------------------------- /debian-10-amd64-proxmox/playbook/requirements.yml: -------------------------------------------------------------------------------- 1 | - src: https://github.com/chriswayg/ansible-initial-server.git 2 | #version: v1.7 3 | -------------------------------------------------------------------------------- /debian-10-amd64-proxmox/playbook/server-template-vars.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | iserver_hostname: deb10-kvm 4 | iserver_sshkey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDK1zNq5zsVbbN/gLdYqxlb5CROsR1dBNBgRFzzCJUL3ncU2dDHLHWi0L/FafwWt6MQ7vePu7catLDegY2fs1QB0KYvy21fD3+9ONBs7KcFlmuyqjLJ9VAoLWW5Tv3I9eZNgpd9k6CvYphKa1Owq43ye+quQRI4J+2nb7Zhl2WTQ1N2WBwZbmf0ErTHwa+mC7frTRBYh6ddyXp9KRULH89y/6cVpL6uQyFzIr6yWowUbJ8lX3fA9e7RAxkG76X54sMa65oq3Bog04ylJ4n/xZCXO449BZjAZHcJuDcFLXrwIo52t+Q6gIEnXInTiii26/ZWbnzzheggjkpQ77tCg03t christian@Chris-GigaMac.local" 5 | 6 | iserver_debian_repos: 7 | - deb http://repo.myloc.de/debian buster main non-free contrib 8 | - deb-src http://repo.myloc.de/debian buster main non-free contrib 9 | - deb http://security.debian.org/debian-security buster/updates main contrib non-free 10 | - deb-src http://security.debian.org/debian-security buster/updates main contrib non-free 11 | - deb http://deb.debian.org/debian buster-updates main contrib non-free 12 | - deb-src http://deb.debian.org/debian buster-updates main contrib non-free 13 | -------------------------------------------------------------------------------- /debian-10-amd64-proxmox/playbook/server-template.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Any remote_user defined in tasks will be ignored. 3 | # Packer will always connect with the user given in the json config for this provisioner. 4 | # https://www.packer.io/docs/provisioners/ansible.html 5 | 6 | # TODO: For unclear reasons, I could only get it to work with the root user in Packer 7 | # 'become' in playbook or role tasks seem to be ignored by Packer Ansible 8 | 9 | - name: Initial configuration of a server. 10 | hosts: all 11 | vars_files: 12 | - server-template-vars.yml 13 | roles: 14 | - role: ansible-initial-server 15 | vars: 16 | iserver_user: "{{ vm_default_user }}" 17 | -------------------------------------------------------------------------------- /debian-10-amd64-proxmox/preseed.cfg.j2: -------------------------------------------------------------------------------- 1 | #### Preseed template-file for Debian 10 buster 2 | # Docs: - https://www.debian.org/releases/stable/amd64/apb.en.html 3 | # - https://www.debian.org/releases/buster/example-preseed.txt 4 | # - Notes: Debian 10 auto-install from ISO using preseed.cfg 5 | 6 | ### Localization 7 | # Locale sets language and country. 8 | d-i debian-installer/locale string en_US.utf8 9 | # Keyboard selection. 10 | d-i keyboard-configuration/xkb-keymap select us 11 | 12 | ### Mirror settings 13 | d-i mirror/country string manual 14 | d-i mirror/http/hostname string http.us.debian.org 15 | d-i mirror/http/directory string /debian 16 | d-i mirror/http/proxy string 17 | 18 | ### Clock and time zone setup 19 | # Controls whether or not the hardware clock is set to UTC. 20 | d-i clock-setup/utc boolean true 21 | # see ls -R /usr/share/zoneinfo/ for valid values. 22 | d-i time/zone string UTC 23 | 24 | ### Partitioning 25 | # This creates an unencrypted primary ext4 partition without swap. 26 | d-i partman-auto/disk string /dev/sda 27 | d-i partman-auto/method string regular 28 | d-i partman-auto/choose_recipe select unencrypted-install 29 | d-i partman-basicfilesystems/no_swap boolean false 30 | d-i partman-auto/expert_recipe string \ 31 | root :: \ 32 | 8190 100000 -1 ext4 \ 33 | $primary{ } $bootable{ } \ 34 | method{ format } format{ } \ 35 | use_filesystem{ } filesystem{ ext4 } \ 36 | mountpoint{ / } \ 37 | . 38 | d-i partman-partitioning/confirm_write_new_label boolean true 39 | d-i partman/choose_partition select finish 40 | d-i partman/confirm boolean true 41 | d-i partman/confirm_nooverwrite boolean true 42 | 43 | ### Account setup 44 | # Default user '{{ env("vm_default_user") }}' 45 | d-i passwd/root-login boolean true 46 | d-i passwd/user-fullname string {{ env("vm_default_user") }} 47 | d-i passwd/username string {{ env("vm_default_user") }} 48 | d-i user-setup/encrypt-home boolean false 49 | # Encrypted root and user passwords 50 | d-i passwd/root-password-crypted password {{ env("password_hash1") }} 51 | d-i passwd/user-password-crypted password {{ env("password_hash2") }} 52 | 53 | ### Apt setup 54 | # prevent the installer from asking about scanning another CD 55 | apt-cdrom-setup apt-setup/cdrom/set-first boolean false 56 | 57 | ### Package selection 58 | tasksel tasksel/first multiselect ssh-server, standard system utilities 59 | # Full upgrade packages after debootstrap and unattended upgrades 60 | d-i pkgsel/upgrade select full-upgrade 61 | d-i pkgsel/update-policy select unattended-upgrades 62 | # Individual additional packages to install 63 | # - qemu-guest-agent for Packer and Proxmox; haveged random generator speeds up boot 64 | d-i pkgsel/include string openssh-server sudo qemu-guest-agent haveged python-apt 65 | d-i pkgsel/install-language-support boolean false 66 | # Do not report back on what software is installed, and what software is used 67 | popularity-contest popularity-contest/participate boolean false 68 | 69 | ### Boot loader installation 70 | d-i grub-installer/bootdev string /dev/sda 71 | 72 | ### Run custom commands during the installation 73 | d-i preseed/late_command string sed -i '/^deb cdrom:/s/^/#/' /target/etc/apt/sources.list 74 | # Enable passwordless sudo for default user and permit root login for Packer Ansible provisioner to work 75 | d-i preseed/late_command string \ 76 | echo '{{ env("vm_default_user") }} ALL=(ALL:ALL) NOPASSWD: ALL' >> /target/etc/sudoers.d/default-user && chmod 440 /target/etc/sudoers.d/default-user && \ 77 | sed -i "/^#PermitRootLogin/c\PermitRootLogin yes" /target/etc/ssh/sshd_config 78 | 79 | ### Finishing up the installation 80 | # Avoid that last message about the install being complete. 81 | d-i finish-install/reboot_in_progress note 82 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/README.md: -------------------------------------------------------------------------------- 1 | ## OpenBSD 6.6 Packer Template using [Packer Proxmox Builder](https://www.packer.io/docs/builders/proxmox.html) to build a Proxmox KVM image template 2 | 3 | Status: **working well** 4 | 5 | - downloads the ISO and places it in Proxmox 6 | - creates a Proxmox VM 7 | - builds the image using install.conf and Ansible 8 | - stores it as a Proxmox Template 9 | 10 | ### Configurations 11 | - there is no qemu guest agent for Packer SSH, therefore we use a static local IP during installation via Packer 12 | - passwordless doas for default user 'deploy' (name can be changed in build.conf) 13 | - SSH public key installed for default user 14 | - display IP and SSH fingerprint before console login (not yet implemented) 15 | - generates new SSH host keys on first boot to avoid duplicates in cloned VMs 16 | - OpenBSD has no cloud utils with growpart to automatically grow partition after resize by Proxmox 17 | 18 | ### Instructions 19 | 20 | - [REAMDE with Prerequisites and Usage](https://github.com/chriswayg/packer-proxmox-templates/blob/master/README.md) 21 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/build.conf: -------------------------------------------------------------------------------- 1 | vm_default_user=christian 2 | vm_memory=1024 3 | default_vm_id=47000 # default VM ID for OpenBSD 4 | proxmox_url=https://proxmox.lightinasia.site:8006/api2/json 5 | proxmox_host=proxmox 6 | 7 | iso_url=https://cloudflare.cdn.openbsd.org/pub/OpenBSD/6.6/amd64/install66.iso 8 | iso_sha256_url=https://cloudflare.cdn.openbsd.org/pub/OpenBSD/6.6/amd64/SHA256 9 | iso_directory=/var/lib/vz/template/iso 10 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/debug/filesets.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | printf "\nFound OpenBSD file sets:\n" 5 | [[ -f /bsd.sp ]] && printf "[X] bsd\n" 6 | [[ -f /bsd ]] && [[ -f /bsd.mp ]] && printf "[X] bsd\n" 7 | [[ -f /bsd.mp ]] && printf "[X] bsd.mp\n" 8 | [[ -f /bsd ]] && [[ -f /bsd.sp ]] && printf "[X] bsd.mp\n" 9 | [[ -f /bsd.rd ]] && printf "[X] bsd.rd\n" 10 | [[ -f /sbin/dmesg ]] && printf "[X] base65\n" 11 | [[ -f /usr/bin/g++ ]] && printf "[X] comp65\n" 12 | [[ -f /usr/games/worm ]] && printf "[X] game65\n" 13 | [[ -f /usr/share/man/man5/fstab.5 ]] && printf "[X] man65\n" 14 | [[ -f /usr/X11R6/bin/xhost ]] && printf "[X] xbase65\n" 15 | [[ -f /usr/X11R6/lib/X11/fonts/100dpi/courR12.pcf.gz ]] && printf "[X] xfont65\n" 16 | [[ -f /usr/X11R6/bin/Xorg ]] && printf "[X] xserv65\n" 17 | [[ -f /usr/X11R6/bin/x11perfcomp ]] && printf "[X] xshare65\n" 18 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/install.conf.j2: -------------------------------------------------------------------------------- 1 | System hostname = openbsd 2 | IPv4 address for vio0 = 10.10.10.252 3 | Default IPv4 route = 10.10.10.1 4 | DNS nameservers = 1.1.1.1 1.0.0.1 5 | Password for root account = {{ env("password_hash1") }} 6 | Do you expect to run the X Window System = no 7 | Setup a user = {{ env("vm_default_user") }} 8 | Password for user {{ env("vm_default_user") }} = {{ env("password_hash2") }} 9 | Allow root ssh login = yes 10 | # Set name(s) = -comp* -game* -x* 11 | Directory does not contain SHA256.sig. Continue without verification = yes 12 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/install.conf.j2.test: -------------------------------------------------------------------------------- 1 | System hostname = openbsd 2 | IPv4 address for vio0 = 10.10.10.252 3 | Default IPv4 route = 10.10.10.1 4 | DNS nameservers = 1.1.1.1 1.0.0.1 5 | Password for root account = {{ env("password_hash1") }} 6 | Do you expect to run the X Window System = no 7 | Setup a user = christian 8 | Password for user christian = {{ env("password_hash2") }} 9 | Allow root ssh login = yes 10 | Set name(s) = -comp* -game* -x* 11 | Directory does not contain SHA256.sig. Continue without verification = yes 12 | 13 | # use a static IP for SSH from packer, then switch back to dhcp for template 14 | 15 | System hostname = openbsd 16 | Which network interface do you wish to configure = vio0 17 | IPv4 address for vio0 = dhcp 18 | IPv6 address for vio0 = none 19 | Which network interface do you wish to configure = done 20 | Public ssh key for root account = none 21 | Start sshd(8) by default = yes 22 | Do you expect to run the X Window System = no 23 | Setup a user = no 24 | Allow root ssh login = yes 25 | What timezone are you in = Asia/Manila 26 | Which disk is the root disk = sd0 27 | Use (W)hole disk MBR, whole disk (G)PT or (E)dit = whole 28 | URL to autopartitioning template for disklabel = none 29 | Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout = a 30 | Location of sets = cd0 31 | Pathname to the sets = 6.5/amd64 32 | Set name(s) = -comp* -game* -x* 33 | Set name(s) = done 34 | Directory does not contain SHA256.sig. Continue without verification = yes 35 | Location of sets = done 36 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/openbsd-6-amd64-proxmox.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Build OpenBSD 6 x86_64 Proxmox template", 3 | "variables": { 4 | "proxmox_url": "{{env `proxmox_url`}}", 5 | "proxmox_username": "root@pam", 6 | "proxmox_password": "{{env `proxmox_password`}}", 7 | "proxmox_host": "{{env `proxmox_host`}}", 8 | "iso_filename": "{{env `iso_filename`}}", 9 | "vm_id": "{{env `vm_id`}}", 10 | "vm_name": "openbsd6-tmpl", 11 | "template_description": "OpenBSD 6 x86_64 template built with packer ({{env `vm_ver`}}). Username: {{env `vm_default_user`}}", 12 | "vm_default_user": "{{env `vm_default_user`}}", 13 | "vm_memory": "{{env `vm_memory`}}", 14 | "ssh_username": "root", 15 | "ssh_password": "{{env `ssh_password`}}", 16 | "ansible_verbosity":"{{env `ansible_verbosity`}}" 17 | }, 18 | "sensitive-variables": ["proxmox_password", "ssh_password" ], 19 | "provisioners": [ 20 | { 21 | "type": "ansible", 22 | "playbook_file": "./playbook/server-template.yml", 23 | "extra_arguments": [ 24 | "{{user `ansible_verbosity`}}", 25 | "--extra-vars", "vm_default_user={{user `vm_default_user`}}", 26 | "--tags", "all,is_template", 27 | "--skip-tags", "debuntu,alpine" 28 | ], 29 | "ansible_env_vars": [ "ANSIBLE_CONFIG=./playbook/ansible.cfg", "ANSIBLE_FORCE_COLOR=True" ] 30 | } 31 | ], 32 | "builders": [ 33 | { 34 | "type": "proxmox", 35 | "proxmox_url": "{{user `proxmox_url`}}", 36 | "insecure_skip_tls_verify": true, 37 | "username": "{{user `proxmox_username`}}", 38 | "password": "{{user `proxmox_password`}}", 39 | "vm_id": "{{user `vm_id`}}", 40 | "vm_name": "{{user `vm_name`}}", 41 | "template_description":"{{user `template_description`}}", 42 | "memory": "{{user `vm_memory`}}", 43 | "cores": "2", 44 | "os": "other", 45 | "http_directory": "http", 46 | 47 | "node": "{{user `proxmox_host`}}", 48 | "network_adapters": [ 49 | { 50 | "model": "virtio", 51 | "bridge": "vmbr1" 52 | } 53 | ], 54 | "disks": [ 55 | { 56 | "type": "scsi", 57 | "disk_size": "8G", 58 | "storage_pool": "local", 59 | "storage_pool_type": "directory", 60 | "format": "qcow2" 61 | } 62 | ], 63 | "ssh_username": "{{user `ssh_username`}}", 64 | "ssh_password": "{{user `ssh_password`}}", 65 | "ssh_timeout": "15m", 66 | "ssh_host": "10.10.10.252", 67 | "qemu_agent": false, 68 | "iso_file": "local:iso/{{user `iso_filename`}}", 69 | "unmount_iso": true, 70 | "boot_wait": "30s", 71 | "boot_command": [ 72 | "a", 73 | "", 74 | "http://{{ .HTTPIP }}:{{ .HTTPPort }}/install.conf", 75 | "", 76 | "i" 77 | ] 78 | } 79 | ], 80 | "post-processors": [ 81 | { 82 | "type": "shell-local", 83 | "inline_shebang": "/bin/bash -e", 84 | "inline": ["qm set {{user `vm_id`}} --scsihw virtio-scsi-pci --serial0 socket --vga serial0"] 85 | } 86 | ] 87 | } 88 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/playbook/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | deprecation_warnings = False 3 | host_key_checking = False 4 | callback_whitelist = timer, profile_roles 5 | stdout_callback = yaml 6 | roles_path = ./roles 7 | log_path = ./logs/server-template.log 8 | inventory = ./hosts 9 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/playbook/hosts: -------------------------------------------------------------------------------- 1 | [servers] 2 | 3 | OpenBSD ansible_host=10.10.10.252 ansible_port=22 4 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/playbook/requirements.yml: -------------------------------------------------------------------------------- 1 | - src: https://github.com/chriswayg/ansible-initial-server.git 2 | #version: v1.7 3 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/playbook/server-template-vars.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | iserver_hostname: openbsd6 4 | iserver_sshkey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDK1zNq5zsVbbN/gLdYqxlb5CROsR1dBNBgRFzzCJUL3ncU2dDHLHWi0L/FafwWt6MQ7vePu7catLDegY2fs1QB0KYvy21fD3+9ONBs7KcFlmuyqjLJ9VAoLWW5Tv3I9eZNgpd9k6CvYphKa1Owq43ye+quQRI4J+2nb7Zhl2WTQ1N2WBwZbmf0ErTHwa+mC7frTRBYh6ddyXp9KRULH89y/6cVpL6uQyFzIr6yWowUbJ8lX3fA9e7RAxkG76X54sMa65oq3Bog04ylJ4n/xZCXO449BZjAZHcJuDcFLXrwIo52t+Q6gIEnXInTiii26/ZWbnzzheggjkpQ77tCg03t christian@Chris-GigaMac.local" 5 | -------------------------------------------------------------------------------- /openbsd-6-amd64-proxmox/playbook/server-template.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Any remote_user defined in tasks will be ignored. 3 | # Packer will always connect with the user given in the json config for this provisioner. 4 | # https://www.packer.io/docs/provisioners/ansible.html 5 | 6 | # TODO: For unclear reasons, I could only get it to work with the root user in Packer 7 | # 'become' in playbook or role tasks seem to be ignored by Packer Ansible 8 | 9 | - name: Prepare OpenBSD for Ansible. 10 | hosts: all 11 | gather_facts: False 12 | tasks: 13 | - name: Ensure, that python is installed. 14 | raw: pkg_add -z python-2.7 15 | 16 | - name: Ensure that python 2 is linked to /usr/bin/python. 17 | raw: ln -sf /usr/local/bin/python2.7 /usr/bin/python 18 | 19 | - name: Initial configuration of a server. 20 | hosts: all 21 | vars_files: 22 | - server-template-vars.yml 23 | roles: 24 | - role: ansible-initial-server 25 | vars: 26 | iserver_user: "{{ vm_default_user }}" 27 | iserver_become: su 28 | -------------------------------------------------------------------------------- /ubuntu-18.04-amd64-proxmox/README.md: -------------------------------------------------------------------------------- 1 | ## [Ubuntu ](http://releases.ubuntu.com/18.04/) 18.04 (bionic) Packer Template using [Packer Proxmox Builder](https://www.packer.io/docs/builders/proxmox.html) to build a Proxmox KVM image template 2 | 3 | Status: **working well** 4 | 5 | - downloads the ISO and places it in Proxmox 6 | - creates a Proxmox VM 7 | - builds the image using preseed.cfg and Ansible 8 | - stores it as a Proxmox Template 9 | 10 | ### Configurations 11 | - qemu-guest-agent for Packer SSH and in Proxmox for shutdown and backups 12 | - haveged random number generator to speed up boot 13 | - passwordless sudo for default user 'deploy' (name can be changed in build.conf) 14 | - SSH public key installed for default user 15 | - display IP and SSH fingerprint before console login 16 | - generates new SSH host keys on first boot to avoid duplicates in cloned VMs 17 | - automatically grow partition after resize by Proxmox 18 | 19 | ### Instructions 20 | 21 | - [REAMDE with Prerequisites and Usage](https://github.com/chriswayg/packer-proxmox-templates/blob/master/README.md) 22 | -------------------------------------------------------------------------------- /ubuntu-18.04-amd64-proxmox/build.conf: -------------------------------------------------------------------------------- 1 | vm_default_user=christian 2 | vm_memory=1024 3 | default_vm_id=20000 # default VM ID for Ubuntu 4 | proxmox_url=https://proxmox.lightinasia.site:8006/api2/json 5 | proxmox_host=proxmox 6 | 7 | iso_url=http://cdimage.ubuntu.com/releases/18.04.4/release/ubuntu-18.04.4-server-amd64.iso 8 | iso_sha256_url=http://cdimage.ubuntu.com/releases/18.04.4/release/SHA256SUMS 9 | iso_directory=/var/lib/vz/template/iso 10 | -------------------------------------------------------------------------------- /ubuntu-18.04-amd64-proxmox/debug/packer-ansible.sh: -------------------------------------------------------------------------------- 1 | # command used by Packer to run ansible playbook 2 | 3 | ansible-playbook /root/packer-projects/ubuntu-18.04-amd64-proxmox/playbook/server-template.yml 4 | -vv 5 | --inventory-file /tmp/packer-provisioner-ansible121990355 6 | --extra-vars 7 | packer_build_name=proxmox 8 | packer_builder_type=proxmox 9 | packer_http_addr=217.79.184.184:8320 10 | vm_default_user=chris 11 | ansible_ssh_private_key_file=/tmp/ansible-key088836676 12 | -o IdentitiesOnly=yes # SSH option 13 | -------------------------------------------------------------------------------- /ubuntu-18.04-amd64-proxmox/playbook/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | deprecation_warnings = False 3 | host_key_checking = False 4 | callback_whitelist = timer, profile_roles 5 | stdout_callback = yaml 6 | roles_path = ./roles 7 | log_path = ./logs/server-template.log 8 | 9 | [ssh_connection] 10 | pipelining = True 11 | -------------------------------------------------------------------------------- /ubuntu-18.04-amd64-proxmox/playbook/requirements.yml: -------------------------------------------------------------------------------- 1 | - src: https://github.com/chriswayg/ansible-initial-server.git 2 | #version: v1.7 3 | -------------------------------------------------------------------------------- /ubuntu-18.04-amd64-proxmox/playbook/server-template-vars.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | iserver_hostname: ubuntu1804-kvm 4 | iserver_sshkey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDK1zNq5zsVbbN/gLdYqxlb5CROsR1dBNBgRFzzCJUL3ncU2dDHLHWi0L/FafwWt6MQ7vePu7catLDegY2fs1QB0KYvy21fD3+9ONBs7KcFlmuyqjLJ9VAoLWW5Tv3I9eZNgpd9k6CvYphKa1Owq43ye+quQRI4J+2nb7Zhl2WTQ1N2WBwZbmf0ErTHwa+mC7frTRBYh6ddyXp9KRULH89y/6cVpL6uQyFzIr6yWowUbJ8lX3fA9e7RAxkG76X54sMa65oq3Bog04ylJ4n/xZCXO449BZjAZHcJuDcFLXrwIo52t+Q6gIEnXInTiii26/ZWbnzzheggjkpQ77tCg03t christian@Chris-GigaMac.local" 5 | 6 | iserver_ubuntu_repos: 7 | - deb http://repo.myloc.de/ubuntu/ bionic main restricted universe multiverse 8 | - deb-src http://repo.myloc.de/ubuntu/ bionic main restricted universe multiverse 9 | - deb http://repo.myloc.de/ubuntu/ bionic-updates main restricted universe multiverse 10 | - deb-src http://repo.myloc.de/ubuntu/ bionic-updates main restricted universe multiverse 11 | - deb http://repo.myloc.de/ubuntu/ bionic-backports main restricted universe multiverse 12 | - deb-src http://repo.myloc.de/ubuntu/ bionic-backports main restricted universe multiverse 13 | - deb http://security.ubuntu.com/ubuntu bionic-security main restricted universe multiverse 14 | - deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted universe multiverse 15 | -------------------------------------------------------------------------------- /ubuntu-18.04-amd64-proxmox/playbook/server-template.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Any remote_user defined in tasks will be ignored. 3 | # Packer will always connect with the user given in the json config for this provisioner. 4 | # https://www.packer.io/docs/provisioners/ansible.html 5 | 6 | # TODO: For unclear reasons, I could only get it to work with the root user in Packer. 7 | # 'become' in playbook or role tasks seems to be ignored by Packer Ansible 8 | 9 | - name: Initial configuration of a server. 10 | hosts: all 11 | vars_files: 12 | - server-template-vars.yml 13 | roles: 14 | - role: ansible-initial-server 15 | vars: 16 | iserver_user: "{{ vm_default_user }}" 17 | -------------------------------------------------------------------------------- /ubuntu-18.04-amd64-proxmox/preseed.cfg.j2: -------------------------------------------------------------------------------- 1 | #### Preseed file for Ubuntu 18.04 bionic 2 | # Docs: - https://help.ubuntu.com/lts/installation-guide/amd64/apbs01.html 3 | # - https://help.ubuntu.com/18.04/installation-guide/example-preseed.txt 4 | 5 | ### Localization 6 | # Locale sets language and country. 7 | d-i debian-installer/locale string en_US.utf8 8 | # Keyboard selection. 9 | d-i keyboard-configuration/xkb-keymap select us 10 | 11 | ### Mirror settings 12 | d-i mirror/country string manual 13 | d-i mirror/http/hostname string archive.ubuntu.com 14 | d-i mirror/http/directory string /ubuntu 15 | d-i mirror/http/proxy string 16 | 17 | ### Clock and time zone setup 18 | # Controls whether or not the hardware clock is set to UTC. 19 | d-i clock-setup/utc boolean true 20 | # see ls -R /usr/share/zoneinfo/ for valid values. 21 | d-i time/zone string UTC 22 | 23 | ### Partitioning 24 | # This creates an unencrypted primary ext4 partition without swap. 25 | d-i partman-auto/disk string /dev/sda 26 | d-i partman-auto/method string regular 27 | d-i partman-auto/choose_recipe select unencrypted-install 28 | d-i partman-basicfilesystems/no_swap boolean false 29 | d-i partman-auto/expert_recipe string \ 30 | root :: \ 31 | 8190 100000 -1 ext4 \ 32 | $primary{ } $bootable{ } \ 33 | method{ format } format{ } \ 34 | use_filesystem{ } filesystem{ ext4 } \ 35 | mountpoint{ / } \ 36 | . 37 | d-i partman-partitioning/confirm_write_new_label boolean true 38 | d-i partman/choose_partition select finish 39 | d-i partman/confirm boolean true 40 | d-i partman/confirm_nooverwrite boolean true 41 | 42 | ### Account setup 43 | # Default user '{{ env("vm_default_user") }}' 44 | d-i passwd/root-login boolean true 45 | d-i passwd/user-fullname string {{ env("vm_default_user") }} 46 | d-i passwd/username string {{ env("vm_default_user") }} 47 | d-i user-setup/encrypt-home boolean false 48 | # Encrypted root and user passwords 49 | d-i passwd/root-password-crypted password {{ env("password_hash1") }} 50 | d-i passwd/user-password-crypted password {{ env("password_hash2") }} 51 | 52 | ### Package selection 53 | tasksel tasksel/first multiselect standard, server 54 | # Full upgrade packages after debootstrap and unattended upgrades 55 | d-i pkgsel/upgrade select full-upgrade 56 | d-i pkgsel/update-policy select unattended-upgrades 57 | # Individual additional packages to install 58 | # - qemu-guest-agent needed for packer; better random generator speeds up boot 59 | d-i pkgsel/include string openssh-server sudo qemu-guest-agent haveged python-apt 60 | d-i pkgsel/install-language-support boolean false 61 | # Do not report back on what software is installed, and what software is used 62 | popularity-contest popularity-contest/participate boolean false 63 | 64 | ### Boot loader installation 65 | d-i grub-installer/bootdev string /dev/sda 66 | 67 | ### Run custom commands during the installation 68 | # Enable passwordless sudo for default user and permit root login for Packer Ansible provisioner to work 69 | d-i preseed/late_command string \ 70 | echo '{{ env("vm_default_user") }} ALL=(ALL:ALL) NOPASSWD: ALL' >> /target/etc/sudoers.d/default-user && chmod 440 /target/etc/sudoers.d/default-user && \ 71 | sed -i "/^#PermitRootLogin/c\PermitRootLogin yes" /target/etc/ssh/sshd_config 72 | 73 | ### Finishing up the installation 74 | # Avoid that last message about the install being complete. 75 | d-i finish-install/reboot_in_progress note 76 | -------------------------------------------------------------------------------- /ubuntu-18.04-amd64-proxmox/ubuntu-18.04-amd64-proxmox.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Build Ubuntu 18.04 (bionic) x86_64 Proxmox template", 3 | "variables": { 4 | "proxmox_url": "{{env `proxmox_url`}}", 5 | "proxmox_username": "root@pam", 6 | "proxmox_password": "{{env `proxmox_password`}}", 7 | "proxmox_host": "{{env `proxmox_host`}}", 8 | "iso_filename": "{{env `iso_filename`}}", 9 | "vm_id": "{{env `vm_id`}}", 10 | "vm_name": "ubuntu1804-tmpl", 11 | "template_description": "Ubuntu 18.04 x86_64 template built with packer ({{env `vm_ver`}}). Username: {{env `vm_default_user`}}", 12 | "vm_default_user": "{{env `vm_default_user`}}", 13 | "vm_memory": "{{env `vm_memory`}}", 14 | "ssh_username": "root", 15 | "ssh_password": "{{env `ssh_password`}}" 16 | }, 17 | "sensitive-variables": ["proxmox_password", "ssh_password" ], 18 | "provisioners": [ 19 | { 20 | "type": "ansible", 21 | "playbook_file": "./playbook/server-template.yml", 22 | "extra_arguments": [ 23 | "{{user `ansible_verbosity`}}", 24 | "--extra-vars", "vm_default_user={{user `vm_default_user`}}", 25 | "--tags", "all,is_template", 26 | "--skip-tags", "openbsd,alpine" 27 | ], 28 | "ansible_env_vars": [ "ANSIBLE_CONFIG=./playbook/ansible.cfg", "ANSIBLE_FORCE_COLOR=True" ] 29 | } 30 | ], 31 | "builders": [ 32 | { 33 | "type": "proxmox", 34 | "proxmox_url": "{{user `proxmox_url`}}", 35 | "insecure_skip_tls_verify": true, 36 | "username": "{{user `proxmox_username`}}", 37 | "password": "{{user `proxmox_password`}}", 38 | "vm_id": "{{user `vm_id`}}", 39 | "vm_name": "{{user `vm_name`}}", 40 | "template_description":"{{user `template_description`}}", 41 | "memory": "{{user `vm_memory`}}", 42 | "cores": "2", 43 | "os": "l26", 44 | "http_directory": "http", 45 | 46 | "node": "{{user `proxmox_host`}}", 47 | "network_adapters": [ 48 | { 49 | "model": "virtio", 50 | "bridge": "vmbr1" 51 | } 52 | ], 53 | "disks": [ 54 | { 55 | "type": "scsi", 56 | "disk_size": "8G", 57 | "storage_pool": "local", 58 | "storage_pool_type": "directory", 59 | "format": "qcow2" 60 | } 61 | ], 62 | "ssh_username": "{{user `ssh_username`}}", 63 | "ssh_password": "{{user `ssh_password`}}", 64 | "ssh_timeout": "15m", 65 | "iso_file": "local:iso/{{user `iso_filename`}}", 66 | "unmount_iso": true, 67 | "boot_wait": "10s", 68 | "boot_command": [ 69 | "", 70 | "", 71 | "", 72 | "/install/vmlinuz initrd=/install/initrd.gz", 73 | " auto=true priority=critical", 74 | " url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", 75 | "" 76 | ] 77 | } 78 | ], 79 | "post-processors": [ 80 | { 81 | "type": "shell-local", 82 | "inline_shebang": "/bin/bash -e", 83 | "inline": ["qm set {{user `vm_id`}} --scsihw virtio-scsi-pci --serial0 socket --vga serial0"] 84 | } 85 | ] 86 | } 87 | -------------------------------------------------------------------------------- /ubuntu-20.04-amd64-proxmox/README.md: -------------------------------------------------------------------------------- 1 | ## [Ubuntu ](http://releases.ubuntu.com/20.04/) 20.04 (focal) Packer Template using [Packer Proxmox Builder](https://www.packer.io/docs/builders/proxmox.html) to build a Proxmox KVM image template 2 | 3 | Status: **working well** 4 | 5 | - downloads the ISO and places it in Proxmox 6 | - creates a Proxmox VM 7 | - builds the image using preseed.cfg and Ansible 8 | - stores it as a Proxmox Template 9 | 10 | ### Configurations 11 | - qemu-guest-agent for Packer SSH and in Proxmox for shutdown and backups 12 | - haveged random number generator to speed up boot 13 | - passwordless sudo for default user 'deploy' (name can be changed in build.conf) 14 | - SSH public key installed for default user 15 | - display IP and SSH fingerprint before console login 16 | - generates new SSH host keys on first boot to avoid duplicates in cloned VMs 17 | - automatically grow partition after resize by Proxmox 18 | 19 | ### Instructions 20 | 21 | - [REAMDE with Prerequisites and Usage](https://github.com/chriswayg/packer-proxmox-templates/blob/master/README.md) 22 | -------------------------------------------------------------------------------- /ubuntu-20.04-amd64-proxmox/build.conf: -------------------------------------------------------------------------------- 1 | vm_default_user=christian 2 | vm_memory=1024 3 | default_vm_id=21000 # default VM ID for Ubuntu 4 | proxmox_url=https://proxmox.lightinasia.site:8006/api2/json 5 | proxmox_host=proxmox 6 | 7 | iso_url=http://cdimage.ubuntu.com/ubuntu-legacy-server/releases/20.04/release/ubuntu-20.04-legacy-server-amd64.iso 8 | iso_sha256_url=http://cdimage.ubuntu.com/ubuntu-legacy-server/releases/20.04/release/SHA256SUMS 9 | iso_directory=/var/lib/vz/template/iso 10 | -------------------------------------------------------------------------------- /ubuntu-20.04-amd64-proxmox/playbook/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | deprecation_warnings = False 3 | host_key_checking = False 4 | callback_whitelist = timer, profile_roles 5 | stdout_callback = yaml 6 | roles_path = ./roles 7 | log_path = ./logs/server-template.log 8 | 9 | [ssh_connection] 10 | pipelining = True 11 | -------------------------------------------------------------------------------- /ubuntu-20.04-amd64-proxmox/playbook/requirements.yml: -------------------------------------------------------------------------------- 1 | - src: https://github.com/chriswayg/ansible-initial-server.git 2 | #version: v1.7 3 | -------------------------------------------------------------------------------- /ubuntu-20.04-amd64-proxmox/playbook/server-template-vars.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | iserver_hostname: ubuntu2004-kvm 4 | iserver_sshkey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDK1zNq5zsVbbN/gLdYqxlb5CROsR1dBNBgRFzzCJUL3ncU2dDHLHWi0L/FafwWt6MQ7vePu7catLDegY2fs1QB0KYvy21fD3+9ONBs7KcFlmuyqjLJ9VAoLWW5Tv3I9eZNgpd9k6CvYphKa1Owq43ye+quQRI4J+2nb7Zhl2WTQ1N2WBwZbmf0ErTHwa+mC7frTRBYh6ddyXp9KRULH89y/6cVpL6uQyFzIr6yWowUbJ8lX3fA9e7RAxkG76X54sMa65oq3Bog04ylJ4n/xZCXO449BZjAZHcJuDcFLXrwIo52t+Q6gIEnXInTiii26/ZWbnzzheggjkpQ77tCg03t christian@Chris-GigaMac.local" 5 | 6 | iserver_ubuntu_repos: 7 | - deb http://repo.myloc.de/ubuntu/ focal main restricted universe multiverse 8 | - deb-src http://repo.myloc.de/ubuntu/ focal main restricted universe multiverse 9 | - deb http://repo.myloc.de/ubuntu/ focal-updates main restricted universe multiverse 10 | - deb-src http://repo.myloc.de/ubuntu/ focal-updates main restricted universe multiverse 11 | - deb http://repo.myloc.de/ubuntu/ focal-backports main restricted universe multiverse 12 | - deb-src http://repo.myloc.de/ubuntu/ focal-backports main restricted universe multiverse 13 | - deb http://security.ubuntu.com/ubuntu focal-security main restricted universe multiverse 14 | - deb-src http://security.ubuntu.com/ubuntu focal-security main restricted universe multiverse 15 | -------------------------------------------------------------------------------- /ubuntu-20.04-amd64-proxmox/playbook/server-template.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Any remote_user defined in tasks will be ignored. 3 | # Packer will always connect with the user given in the json config for this provisioner. 4 | # https://www.packer.io/docs/provisioners/ansible.html 5 | 6 | # TODO: For unclear reasons, I could only get it to work with the root user in Packer. 7 | # 'become' in playbook or role tasks seems to be ignored by Packer Ansible 8 | 9 | - name: Initial configuration of a server. 10 | hosts: all 11 | vars_files: 12 | - server-template-vars.yml 13 | roles: 14 | - role: ansible-initial-server 15 | vars: 16 | iserver_user: "{{ vm_default_user }}" 17 | -------------------------------------------------------------------------------- /ubuntu-20.04-amd64-proxmox/preseed.cfg.j2: -------------------------------------------------------------------------------- 1 | #### Preseed file for Ubuntu 20.04 focal 2 | # Docs: - https://help.ubuntu.com/lts/installation-guide/amd64/apbs01.html 3 | # - https://help.ubuntu.com/20.04/installation-guide/example-preseed.txt 4 | 5 | ### Localization 6 | # Locale sets language and country. 7 | d-i debian-installer/locale string en_US.utf8 8 | # Keyboard selection. 9 | d-i keyboard-configuration/xkb-keymap select us 10 | 11 | ### Mirror settings 12 | d-i mirror/country string manual 13 | d-i mirror/http/hostname string archive.ubuntu.com 14 | d-i mirror/http/directory string /ubuntu 15 | d-i mirror/http/proxy string 16 | 17 | ### Clock and time zone setup 18 | # Controls whether or not the hardware clock is set to UTC. 19 | d-i clock-setup/utc boolean true 20 | # see ls -R /usr/share/zoneinfo/ for valid values. 21 | d-i time/zone string UTC 22 | 23 | ### Partitioning 24 | # This creates an unencrypted primary ext4 partition without swap. 25 | d-i partman-auto/disk string /dev/sda 26 | d-i partman-auto/method string regular 27 | d-i partman-auto/choose_recipe select unencrypted-install 28 | d-i partman-basicfilesystems/no_swap boolean false 29 | d-i partman-auto/expert_recipe string \ 30 | root :: \ 31 | 8190 100000 -1 ext4 \ 32 | $primary{ } $bootable{ } \ 33 | method{ format } format{ } \ 34 | use_filesystem{ } filesystem{ ext4 } \ 35 | mountpoint{ / } \ 36 | . 37 | d-i partman-partitioning/confirm_write_new_label boolean true 38 | d-i partman/choose_partition select finish 39 | d-i partman/confirm boolean true 40 | d-i partman/confirm_nooverwrite boolean true 41 | 42 | ### Account setup 43 | # Default user '{{ env("vm_default_user") }}' 44 | d-i passwd/root-login boolean true 45 | d-i passwd/user-fullname string {{ env("vm_default_user") }} 46 | d-i passwd/username string {{ env("vm_default_user") }} 47 | d-i user-setup/encrypt-home boolean false 48 | # Encrypted root and user passwords 49 | d-i passwd/root-password-crypted password {{ env("password_hash1") }} 50 | d-i passwd/user-password-crypted password {{ env("password_hash2") }} 51 | 52 | ### Package selection 53 | tasksel tasksel/first multiselect standard, server 54 | # Full upgrade packages after debootstrap and unattended upgrades 55 | d-i pkgsel/upgrade select full-upgrade 56 | d-i pkgsel/update-policy select unattended-upgrades 57 | # Individual additional packages to install 58 | # - qemu-guest-agent needed for packer; better random generator speeds up boot 59 | d-i pkgsel/include string openssh-server sudo qemu-guest-agent haveged python-apt 60 | d-i pkgsel/install-language-support boolean false 61 | # Do not report back on what software is installed, and what software is used 62 | popularity-contest popularity-contest/participate boolean false 63 | 64 | ### Boot loader installation 65 | d-i grub-installer/bootdev string /dev/sda 66 | 67 | ### Run custom commands during the installation 68 | # Enable passwordless sudo for default user and permit root login for Packer Ansible provisioner to work 69 | d-i preseed/late_command string \ 70 | echo '{{ env("vm_default_user") }} ALL=(ALL:ALL) NOPASSWD: ALL' >> /target/etc/sudoers.d/default-user && chmod 440 /target/etc/sudoers.d/default-user && \ 71 | sed -i "/^#PermitRootLogin/c\PermitRootLogin yes" /target/etc/ssh/sshd_config 72 | 73 | ### Finishing up the installation 74 | # Avoid that last message about the install being complete. 75 | d-i finish-install/reboot_in_progress note 76 | -------------------------------------------------------------------------------- /ubuntu-20.04-amd64-proxmox/ubuntu-20.04-amd64-proxmox.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Build Ubuntu 20.04 (focal) x86_64 Proxmox template", 3 | "variables": { 4 | "proxmox_url": "{{env `proxmox_url`}}", 5 | "proxmox_username": "root@pam", 6 | "proxmox_password": "{{env `proxmox_password`}}", 7 | "proxmox_host": "{{env `proxmox_host`}}", 8 | "iso_filename": "{{env `iso_filename`}}", 9 | "vm_id": "{{env `vm_id`}}", 10 | "vm_name": "ubuntu2004-tmpl", 11 | "template_description": "Ubuntu 20.04 x86_64 template built with packer ({{env `vm_ver`}}). Username: {{env `vm_default_user`}}", 12 | "vm_default_user": "{{env `vm_default_user`}}", 13 | "vm_memory": "{{env `vm_memory`}}", 14 | "ssh_username": "root", 15 | "ssh_password": "{{env `ssh_password`}}" 16 | }, 17 | "sensitive-variables": ["proxmox_password", "ssh_password" ], 18 | "provisioners": [ 19 | { 20 | "type": "ansible", 21 | "playbook_file": "./playbook/server-template.yml", 22 | "extra_arguments": [ 23 | "{{user `ansible_verbosity`}}", 24 | "--extra-vars", "vm_default_user={{user `vm_default_user`}}", 25 | "--tags", "all,is_template", 26 | "--skip-tags", "openbsd,alpine" 27 | ], 28 | "ansible_env_vars": [ "ANSIBLE_CONFIG=./playbook/ansible.cfg", "ANSIBLE_FORCE_COLOR=True" ] 29 | } 30 | ], 31 | "builders": [ 32 | { 33 | "type": "proxmox", 34 | "proxmox_url": "{{user `proxmox_url`}}", 35 | "insecure_skip_tls_verify": true, 36 | "username": "{{user `proxmox_username`}}", 37 | "password": "{{user `proxmox_password`}}", 38 | "vm_id": "{{user `vm_id`}}", 39 | "vm_name": "{{user `vm_name`}}", 40 | "template_description":"{{user `template_description`}}", 41 | "memory": "{{user `vm_memory`}}", 42 | "cores": "2", 43 | "os": "l26", 44 | "http_directory": "http", 45 | 46 | "node": "{{user `proxmox_host`}}", 47 | "network_adapters": [ 48 | { 49 | "model": "virtio", 50 | "bridge": "vmbr1" 51 | } 52 | ], 53 | "disks": [ 54 | { 55 | "type": "scsi", 56 | "disk_size": "8G", 57 | "storage_pool": "local", 58 | "storage_pool_type": "directory", 59 | "format": "qcow2" 60 | } 61 | ], 62 | "ssh_username": "{{user `ssh_username`}}", 63 | "ssh_password": "{{user `ssh_password`}}", 64 | "ssh_timeout": "15m", 65 | "iso_file": "local:iso/{{user `iso_filename`}}", 66 | "unmount_iso": true, 67 | "boot_wait": "10s", 68 | "boot_command": [ 69 | "", 70 | "", 71 | "", 72 | "/install/vmlinuz initrd=/install/initrd.gz", 73 | " auto=true priority=critical", 74 | " url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", 75 | "" 76 | ] 77 | } 78 | ], 79 | "post-processors": [ 80 | { 81 | "type": "shell-local", 82 | "inline_shebang": "/bin/bash -e", 83 | "inline": ["qm set {{user `vm_id`}} --scsihw virtio-scsi-pci --serial0 socket --vga serial0"] 84 | } 85 | ] 86 | } 87 | --------------------------------------------------------------------------------