geerlingguy.packer-debian
Ansible Role: Packer Debian/Ubuntu Setup for Vagrant VirtualBox
This role sets up Debian/Ubuntu (either minimal or full version) to be packaged into a .box file for Vagrant/VirtualBox or Vagrant/Vmware_desktop using Packer.
Requirements
Before using this role with Packer, you need to have Ansible installed through a shell provisioner and ensure that preliminary VM setup (like adding a vagrant user to the right group and sudoers) is done, usually with a Kickstart installation file (e.g., ks.cfg
) or by preseeding with Packer. A sample array of provisioners for your Packer .json file looks like this:
"provisioners": [
{
"type": "shell",
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
"script": "scripts/ansible.sh"
},
{
"type": "ansible-local",
"playbook_file": "ansible/main.yml",
"role_paths": [
"/Users/jgeerling/Dropbox/VMs/roles/geerlingguy.packer-debian",
]
}
],
The files must include, at minimum:
scripts/ansible.sh:
Example for Ubuntu 16.04
#!/bin/bash -eux
# Install Ansible repository and Ansible.
apt -y install software-properties-common
apt-add-repository ppa:ansible/ansible
apt-get update
apt-get install ansible
Example for Debian 8.8
#!/bin/bash -eux
# Install Ansible repository and Ansible.
apt -y install software-properties-common
echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | tee -a /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
apt -y update
apt -y install ansible
ansible/main.yml:
---
- hosts: all
sudo: yes
gather_facts: yes
roles:
- geerlingguy.packer-debian
You might want to add another shell provisioner to clean up and erase free space using dd
, but it's not necessary (it just helps save some disk space in the Packer-generated .box file).
If you want to add more roles, make sure you include them in the role_paths
array in the .json template file, and then you can add them in main.yml
as usual. The Ansible setup will run locally from within the Linux environment, so all necessary files must be copied over to the VM; the setup for this is in the .json template. For more information, see Ansible Local Provisioner.
Role Variables
Here are the available variables with default values (found in defaults/main.yml):
vmware_install_open_vm_tools: false
(For VMware only) Using the vmware_install_open_vm_tools
variable lets you choose the type of integration components to install in the VMware box. The default value (false
) will install VMware Tools instead of open-vm-tools
.
For more information, see:
Dependencies
None.
Example Playbook
---
- hosts: all
roles:
- geerlingguy.packer-debian
License
MIT / BSD
Author Information
This role was created in 2014 by Jeff Geerling, author of Ansible for DevOps.
Debian/Ubuntu configuration for Packer.
ansible-galaxy install geerlingguy.packer-debian