A simple Packer + Vagrant install of Ubuntu 20.04 (Focal Fossa) LTS server for arm64, to run from my M1 Mac on Parallels Pro (17.1). Currently on MacOS Monterey.
Packer will run the ansible playbook.yml
before the machine is shutdown and exported.
The installation is automated by cloud-init (which reads user-data
). The file meta-data
just needs to be an empty text file (you need to create this - no blank files or folders allowed in gists).
ubuntu2004/
├──http/
│ ├── meta-data
│ └── user-data
├── .gitignore
├── README.md
├── playbook.yml
├── Ubuntu.pkr.hcl
└── Vagrantfile
git clone https://gist.github.com/craig-m-unsw/f457a9a189cd939a73b7d215c22b96e2 ubuntu2004
cd ubuntu2004
mkdir http
touch http/meta-data
mv user-data http/user-data
cat <<'EOF' >> .gitignore
.vagrant
.DS_Store
output-ubuntu-*
*.log
*.box
EOF
Building:
This will produce ubuntu2004.box
, a virtual machine image.
ubnfunc_build () {
export PACKER_LOG=2
export PACKER_LOG_PATH=$(pwd)/packer.log
packer validate Ubuntu.pkr.hcl && packer build Ubuntu.pkr.hcl
};
ubnfunc_build
Running:
The Vagrantfile supports multiple VM, each with own static IP. Edit as needed.
vagrant validate Vagrantfile
vagrant up && vagrant ssh admin
exit
This will start the virtual machine/s and log you into them.
Cleaning:
Rinse and repeat.
ubnfunc_clean () {
vagrant destroy -f
vagrant box remove file://ubuntu.box -f
rm -fv -- packer.log ubuntu2004.box
};
ubnfunc_clean
ubnfunc_build
Dude, I f*cking love you! This gist just rescued me from 16 hours of QEMU and VMware Fusion Tech Preview hell trying to get a basic packer Ubuntu box built on an M1 Mac so I can friggin' iterate on my ansible code locally using Vagrant without firing up cloud machines all over the place.
CAN I BUY YOU A BEER?