|
| 1 | +# Ansible Role: Packer RHEL/CentOS Configuration for Vagrant VirtualBox |
| 2 | + |
| 3 | +[](https://travis-ci.org/geerlingguy/ansible-role-packer-rhel) |
| 4 | + |
| 5 | +This role configures RHEL/CentOS (either minimal or full install) in preparation for it to be packaged as part of a .box file for Vagrant/VirtualBox deployment using [Packer](http://www.packer.io/). |
| 6 | + |
| 7 | +The role may be made more flexible in the future, so it could work with other Linux flavors and/or other Packer builders besides VirtualBox, but I'm currently only focused on VirtualBox, since the main use case right now is developer VMs. |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +Prior to running this role via Packer, you need to make sure Ansible is installed via a shell provisioner, and that preliminary VM configuration (like adding a vagrant user to the appropriate group and the sudoers file) is complete, generally by using a Kickstart installation file (e.g. `ks.cfg`) with Packer. An example array of provisioners for your Packer .json template would be something like: |
| 12 | + |
| 13 | + "provisioners": [ |
| 14 | + { |
| 15 | + "type": "shell", |
| 16 | + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'", |
| 17 | + "script": "scripts/ansible.sh" |
| 18 | + }, |
| 19 | + { |
| 20 | + "type": "ansible-local", |
| 21 | + "playbook_file": "ansible/main.yml", |
| 22 | + "role_paths": [ |
| 23 | + "/Users/jgeerling/Dropbox/VMs/roles/geerlingguy.packer-rhel", |
| 24 | + ] |
| 25 | + } |
| 26 | + ], |
| 27 | + |
| 28 | +The files should contain, at a minimum: |
| 29 | + |
| 30 | +**scripts/ansible.sh**: |
| 31 | + |
| 32 | + #!/bin/bash -eux |
| 33 | + # Add the EPEL repository, and install Ansible. |
| 34 | + rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm |
| 35 | + yum -y install ansible python-setuptools |
| 36 | + |
| 37 | +**ansible/main.yml**: |
| 38 | + |
| 39 | + --- |
| 40 | + - hosts: all |
| 41 | + sudo: yes |
| 42 | + gather_facts: yes |
| 43 | + roles: |
| 44 | + - geerlingguy.packer-rhel |
| 45 | + |
| 46 | +You might also want to add another shell provisioner to run cleanup, erasing free space using `dd`, but this is not required (it will just save a little disk space in the Packer-produced .box file). |
| 47 | + |
| 48 | +If you'd like to add additional roles, make sure you add them to the `role_paths` array in the template .json file, and then you can include them in `main.yml` as you normally would. The Ansible configuration will be run over a local connection from within the Linux environment, so all relevant files need to be copied over to the VM; configuratin for this is in the template .json file. Read more: [Ansible Local Provisioner](http://www.packer.io/docs/provisioners/ansible-local.html). |
| 49 | + |
| 50 | +## Role Variables |
| 51 | + |
| 52 | +None. |
| 53 | + |
| 54 | +## Dependencies |
| 55 | + |
| 56 | +None. |
| 57 | + |
| 58 | +## Example Playbook |
| 59 | + |
| 60 | + - hosts: all |
| 61 | + roles: |
| 62 | + - { role: geerlingguy.packer-rhel } |
| 63 | + |
| 64 | +## License |
| 65 | + |
| 66 | +MIT / BSD |
| 67 | + |
| 68 | +## Author Information |
| 69 | + |
| 70 | +This role was created in 2014 by [Jeff Geerling](http://jeffgeerling.com/), author of [Ansible for DevOps](http://ansiblefordevops.com/). |
0 commit comments