Skip to content

Commit 4f5ffcc

Browse files
committed
Packer build for VirtualBox
Signed-off-by: Bas Meijer <bas.meijer@me.com>
1 parent 3c23946 commit 4f5ffcc

29 files changed

Lines changed: 502 additions & 14 deletions

.ansible-lint

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# https://ansible-lint.readthedocs.io/en/latest/default_rules/
3+
exclude_paths:
4+
- ./.tox
5+
- ./roles/RHEL8-STIG
6+
skip_list:
7+
- experimental # all rules tagged as experimental
8+
...

.gitattributes

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github
2+
# Default behaviour
3+
* text=auto
4+
5+
# Scripts should have Unix endings
6+
*.py text eol=lf
7+
*.sh text eol=lf
8+
9+
# Windows Batch or PowerShell scripts should have CRLF endings
10+
*.bat text eol=crlf
11+
*.ps1 text eol=crlf
12+
13+
# adding github settings to show correct language
14+
*.md linguist-documentation
15+
*.yml linguist-detectable=true
16+
*.j2 linguist-detectable=true
17+
*.py linguist-detectable=true
18+
*.ps1 linguist-detectable=true
19+
*.sh linguist-detectable=true

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.vagrant/
2+
.vscode/
3+
Brewfile.lock.json
4+
output-rhel8/
5+
roles/RHEL8-STIG

.pre-commit-config.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
# https://pre-commit.com/hooks.html
3+
default_language_version:
4+
python: python3.8
5+
exclude: .venv
6+
repos:
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v3.4.0
9+
hooks:
10+
- id: check-added-large-files
11+
- id: check-case-conflict
12+
- id: check-executables-have-shebangs
13+
- id: check-json
14+
- id: check-merge-conflict
15+
- id: detect-private-key
16+
- id: end-of-file-fixer
17+
- id: forbid-new-submodules
18+
- id: requirements-txt-fixer
19+
- id: trailing-whitespace
20+
21+
- repo: https://github.com/adrienverge/yamllint
22+
rev: v1.26.0
23+
hooks:
24+
- id: yamllint
25+
args: [-c=.yamllint]
26+
27+
- repo: https://github.com/ansible-community/ansible-lint.git
28+
rev: v6.4.0
29+
hooks:
30+
- id: ansible-lint
31+
files: \.yml$
32+
33+
- repo: https://github.com/robertdebock/pre-commit
34+
rev: v1.2.2
35+
hooks:
36+
- id: ansible_role_find_unused_variable
37+
- id: ansible_role_find_empty_files
38+
- id: ansible_role_find_empty_directories
39+
40+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
41+
rev: 2.1.5 # or specific git tag
42+
hooks:
43+
- id: shellcheck

.yamllint

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
# https://yamllint.readthedocs.io/en/stable/rules.html
3+
extends: default
4+
ignore: |
5+
.tox/
6+
.cache
7+
8+
rules:
9+
braces:
10+
max-spaces-inside: 1
11+
level: error
12+
brackets:
13+
max-spaces-inside: 1
14+
level: error
15+
indentation:
16+
indent-sequences: consistent
17+
spaces: 2
18+
level: error
19+
line-length:
20+
max: 120
21+
level: warning
22+
key-duplicates: enable
23+
new-line-at-end-of-file: enable
24+
new-lines:
25+
type: unix
26+
trailing-spaces: enable
27+
truthy:
28+
allowed-values: ['true', 'false']
29+
check-keys: false
30+
...

Brewfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cask "vagrant"
2+
cask "virtualbox"
3+
cask "virtualbox-extension-pack"
4+
brew "packer"

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ANSIBLE_DEBUG=1
2+
lint:
3+
vagrant validate
4+
packer validate rhel8.pkr.hcl
5+
ansible-inventory --graph
6+
ansible-lint vagrant-playbook.yml
7+
8+
clean: lint
9+
@vagrant destroy -f
10+
@vagrant box remove rhel8-disa-stig || /usr/bin/true
11+
@rm -rf output-rhel8 .vagrant
12+
13+
output-rhel8/rhel8.box:
14+
packer build rhel8.pkr.hcl
15+
16+
virtualbox: output-rhel8/rhel8.box
17+
vagrant box add --force --name rhel8-disa-stig output-rhel8/rhel8.box
18+
vagrant up rhel8-disa-stig
19+
20+
image: output-rhel8/rhel8.box
21+
22+
all: clean virtualbox

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Provisioning
2+
3+
We create an image with Hashicorp Packer and then use it to create a VM with Vagrant.
4+
5+
`make all`
6+
7+
All you need is to download the RHEL 8.5 ISO and put it in /Users/Shared/rhel-8.5-x86_64-dvd.iso or be logged in to the Red Hat Customer Portal and have the ISO downloaded.
8+
9+
## Packer will create a DISA-STIG compliant image
10+
11+
`make image`
12+
13+
## Vagrant will create a VM from the image and mount the DVD as Yum repo.
14+
15+
`make virtualbox`
16+
17+
# Requirements
18+
19+
### macOS computer
20+
21+
These programs can be installed manually, or with `brew bundle`.
22+
### Apps
23+
- Packer
24+
- VirtualBox
25+
- Vagrante
26+
27+
### Ansible
28+
run `source install.rc` in a terminal to create a Python virtualenv.

Vagrantfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
Vagrant.configure(2) do |config|
5+
6+
if Vagrant.has_plugin?("vagrant-vbguest")
7+
config.vbguest.auto_update = false
8+
end
9+
10+
config.ssh.insert_key = false
11+
config.ssh.verify_host_key = false
12+
config.vm.box_check_update = false
13+
14+
15+
config.vm.provision :ansible do |ansible|
16+
ansible.compatibility_mode = "2.0"
17+
ansible_inventory = "inventories/vagrant.ini"
18+
ansible.galaxy_role_file = "roles/requirements.yml"
19+
ansible.galaxy_roles_path = "roles"
20+
ansible.playbook = "vagrant-playbook.yml"
21+
ansible.verbose = "v"
22+
ansible.groups = {
23+
"podman" => ["rhel8-disa-stig"],
24+
}
25+
end
26+
27+
config.vm.define 'rhel8-disa-stig', autostart: true, primary: true do |rhel8|
28+
rhel8.vm.box = 'rhel8-disa-stig'
29+
rhel8.vm.hostname = 'rhel8-disa-stig'
30+
rhel8.vm.synced_folder ".", disabled: true
31+
rhel8.vm.provider :virtualbox do |virtualbox|
32+
virtualbox.name = 'rhel8-disa-stig'
33+
virtualbox.gui = false
34+
virtualbox.customize ["modifyvm", :id,
35+
"--boot1", "disk",
36+
"--boot2", "net",
37+
"--boot3", "none",
38+
"--boot4", "none",
39+
"--audio", "none",
40+
"--cpus", 2,
41+
"--memory", 4096,
42+
"--vrde", "on",
43+
"--graphicscontroller", "VMSVGA",
44+
"--vram", "128"
45+
]
46+
virtualbox.customize ["storageattach", :id,
47+
"--device", "0",
48+
"--medium", "/Users/Shared/rhel-8.5-x86_64-dvd.iso",
49+
"--port", "1",
50+
"--storagectl", "SATA Controller",
51+
"--type", "dvddrive"
52+
]
53+
end
54+
end
55+
end

Vagrantfile.template

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
Vagrant.configure(2) do |config|
5+
6+
if Vagrant.has_plugin?("vagrant-vbguest")
7+
config.vbguest.auto_update = false
8+
end
9+
10+
config.ssh.insert_key = false
11+
config.ssh.verify_host_key = false
12+
config.vm.box_check_update = false
13+
config.vm.synced_folder ".""", "/vagrant", id: "vagrant-root", disabled: true
14+
15+
config.vm.define 'rhel8' do |srv|
16+
srv.vm.box = 'rhel8-disa-stig'
17+
srv.vm.hostname = 'rhel8-disa-stig'
18+
srv.vm.network 'private_network', ip: '192.168.56.8'
19+
srv.vm.provider :virtualbox do |virtualbox|
20+
virtualbox.name = 'rhel8'
21+
virtualbox.gui = false
22+
virtualbox.customize ["modifyvm", :id, "--memory", 4096]
23+
virtualbox.customize ["modifyvm", :id,
24+
"--boot1", "disk",
25+
"--boot2", "net",
26+
"--boot3", "none",
27+
"--boot4", "none",
28+
"--audio", "none",
29+
"--cpus", 2,
30+
"--memory", 4096,
31+
"--vrde", "on",
32+
"--graphicscontroller", "VMSVGA",
33+
"--vram", "128"
34+
]
35+
end
36+
end
37+
38+
end

0 commit comments

Comments
 (0)