Skip to content

Commit 6f9d737

Browse files
committed
Initial commit
0 parents  commit 6f9d737

27 files changed

+698
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
packer_cache/*
3+
*.box
4+
iso/*
5+
output-virtualbox-iso/*

README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# packer-elixir-phoenix-centos7
2+
3+
Creates virtualbox and vmware boxes for Elixir and Phoenix development based on CentOS 7.
4+
5+
Based on Jeff Geerling's [packer-centos-7](https://github.com/geerlingguy/packer-centos-7).
6+
7+
**Current CentOS Version Used**: 7.2
8+
9+
This example build configuration installs and configures CentOS 7 x86_64 minimal using Ansible, and then generates two Vagrant box files, for:
10+
11+
- VirtualBox
12+
- VMware
13+
14+
The example can be modified to use more Ansible roles, plays, and included playbooks to fully configure (or partially) configure a box file suitable for deployment for development environments.
15+
16+
## Requirements
17+
18+
The following software must be installed/present on your local machine before you can use Packer to build the Vagrant box file:
19+
20+
- [Packer](http://www.packer.io/)
21+
- [Vagrant](http://vagrantup.com/)
22+
- [VirtualBox](https://www.virtualbox.org/) (if you want to build the VirtualBox box)
23+
- [VMware Fusion](http://www.vmware.com/products/fusion/) (or Workstation - if you want to build the VMware box)
24+
- [Ansible](http://docs.ansible.com/intro_installation.html)
25+
26+
You will also need some Ansible roles installed so they can be used in the building of the VM. To install the roles:
27+
28+
1. Run `$ ansible-galaxy install -r requirements.txt` in this directory.
29+
2. If your local Ansible roles path is not the default (`/etc/ansible/roles`), update the `role_paths` inside `centos7.json` to match your custom location.
30+
31+
If you don't have Ansible installed (perhaps you're using a Windows PC?), you can simply clone the required Ansible roles from GitHub directly (use [Ansible Galaxy](https://galaxy.ansible.com/) to get the GitHub repository URLs for each role listed in `requirements.txt`), and update the `role_paths` variable to match the location of the cloned role.
32+
33+
## Usage
34+
35+
Make sure all the required software (listed above) is installed, then cd to the directory containing this README.md file, and run:
36+
37+
$ packer build centos7.json
38+
39+
After a few minutes, Packer should tell you the box was generated successfully.
40+
41+
If you want to only build a box for one of the supported virtualization platforms (e.g. only build the VMware box), add `--only=vmware-iso` to the `packer build` command:
42+
43+
$ packer build --only=vmware-iso centos7.json

ansible/main.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- hosts: all
3+
sudo: yes
4+
gather_facts: yes
5+
6+
roles:
7+
- nfs
8+
- packer-rhel

ansible/roles/nfs/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Ansible Role: NFS
2+
3+
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-nfs.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-nfs)
4+
5+
Installs NFS utilities on RedHat/CentOS or Debian/Ubuntu.
6+
7+
## Requirements
8+
9+
None.
10+
11+
## Role Variables
12+
13+
Available variables are listed below, along with default values (see `defaults/main.yml`):
14+
15+
nfs_exports: []
16+
17+
A list of exports which will be placed in the `/etc/exports` file. See Ubuntu's simple [Network File System (NFS)](https://help.ubuntu.com/14.04/serverguide/network-file-system.html) guide for more info and examples. (Simple example: `nfs_exports: { "/home/public *(rw,sync,no_root_squash)" }`).
18+
19+
## Dependencies
20+
21+
None.
22+
23+
## Example Playbook
24+
25+
- hosts: db-servers
26+
roles:
27+
- { role: geerlingguy.nfs }
28+
29+
## License
30+
31+
MIT / BSD
32+
33+
## Author Information
34+
35+
This role was created in 2014 by [Jeff Geerling](http://jeffgeerling.com/), author of [Ansible for DevOps](http://ansiblefordevops.com/).

ansible/roles/nfs/defaults/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
nfs_exports: []

ansible/roles/nfs/handlers/main.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
- name: restart nfs
3+
service: "name={{ nfs_server_daemon }} state=restarted"
4+
when: nfs_exports|length

ansible/roles/nfs/meta/main.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
dependencies: []
3+
4+
galaxy_info:
5+
author: geerlingguy
6+
description: NFS installation for Linux.
7+
company: "Midwestern Mac, LLC"
8+
license: "license (BSD, MIT)"
9+
min_ansible_version: 2.0
10+
platforms:
11+
- name: EL
12+
versions:
13+
- all
14+
- name: Fedora
15+
versions:
16+
- all
17+
- name: Debian
18+
versions:
19+
- all
20+
- name: Ubuntu
21+
versions:
22+
- all
23+
galaxy_tags:
24+
- system

ansible/roles/nfs/tasks/main.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
# Include variables and define needed variables.
3+
- name: Include OS-specific variables.
4+
include_vars: "{{ ansible_os_family }}.yml"
5+
6+
- name: Include overrides specific to RHEL 7.
7+
include_vars: RedHat-7.yml
8+
when: ansible_os_family == 'RedHat' and ansible_distribution_major_version == "7"
9+
10+
- name: Include overrides specific to Fedora.
11+
include_vars: Fedora.yml
12+
when: ansible_os_family == 'RedHat' and ansible_distribution == "Fedora"
13+
14+
# Setup/install tasks.
15+
- include: setup-RedHat.yml
16+
when: ansible_os_family == 'RedHat'
17+
18+
- include: setup-Debian.yml
19+
when: ansible_os_family == 'Debian'
20+
21+
- name: Ensure directories to export exist
22+
file: 'path="{{ item.strip().split()[0] }}" state=directory'
23+
with_items: "{{ nfs_exports }}"
24+
notify: restart nfs
25+
26+
- name: Copy exports file.
27+
template:
28+
src: exports.j2
29+
dest: /etc/exports
30+
owner: root
31+
group: root
32+
mode: 0644
33+
register: nfs_exports_copy
34+
notify: restart nfs
35+
36+
- name: Restart NFS immediately if exports are updated.
37+
service: "name={{ nfs_server_daemon }} state=restarted"
38+
when: nfs_exports_copy.changed
39+
40+
- name: Ensure nfs is running.
41+
service: "name={{ nfs_server_daemon }} state=started enabled=yes"
42+
when: nfs_exports|length
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: Ensure NFS utilities are installed.
3+
apt: "name={{ item }} state=installed"
4+
with_items:
5+
- nfs-common
6+
- nfs-kernel-server
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
- name: Ensure NFS utilities are installed.
3+
package: name=nfs-utils state=installed
4+
5+
- name: Ensure rpcbind is running.
6+
service: name=rpcbind state=started enabled=yes
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# /etc/exports: the access control list for filesystems which may be exported
2+
# to NFS clients. See exports(5).
3+
#
4+
# Example for NFSv2 and NFSv3:
5+
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
6+
#
7+
# Example for NFSv4:
8+
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
9+
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
10+
#
11+
{% for export in nfs_exports %}
12+
{{ export }}
13+
{% endfor %}

ansible/roles/nfs/vars/Debian.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
nfs_server_daemon: nfs-kernel-server

ansible/roles/nfs/vars/Fedora.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
nfs_server_daemon: nfs-server

ansible/roles/nfs/vars/RedHat-7.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
nfs_server_daemon: nfs-server

ansible/roles/nfs/vars/RedHat.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
nfs_server_daemon: nfs

ansible/roles/packer-rhel/README.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Ansible Role: Packer RHEL/CentOS Configuration for Vagrant VirtualBox
2+
3+
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-packer-rhel.svg?branch=master)](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/).
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
dependencies: []
3+
4+
galaxy_info:
5+
author: geerlingguy
6+
description: RedHat/CentOS configuration for Packer.
7+
company: "Midwestern Mac, LLC"
8+
license: "license (BSD, MIT)"
9+
min_ansible_version: 1.8
10+
platforms:
11+
- name: EL
12+
versions:
13+
- 6
14+
- 7
15+
galaxy_tags:
16+
- cloud
17+
- system
18+
- packaging
19+
- development

0 commit comments

Comments
 (0)