Packer-based tooling to build Beaker-ready Vagrant boxes from SIMP ISO files.
- This version of
simp-packersupports SIMP >= 6.5.0-Alpha - It builds Vagrant boxes for Virtualbox using Vagrant's virtualbox-iso builder.
- See the Roadmap for boxes/features that are currently implemented and planned.
Requirements:
-
Packer (distributed as a binary).
simp-packer>= 2.4 requirespackerversion 1.4.0 or later. It also requires ruby >= 2.3 because of gem dependencies.- Ensure the binary is in your
$PATHand comes before any other packer executables on the system (e.g.,export PATH="/path/to/packer:$PATH").
-
A SIMP ISO (
.iso) file. Either an official release or one generated by simp-core build commands.- (Optional, but useful:) The
.json"vars" file that was generated along with the SIMP.isofile. This file is generated by the SIMP ISO build process.
- (Optional, but useful:) The
There are a few ways to run simp-packer:
-
- still under development and has not been thoroughly tested.
- Builds multiple Vagrant boxes based on a matrix of settings.
- Publishes each box plus JSON files with versioned metadata to
a local directory tree.
- Beaker,
Vagrantfiles, andvagrant initcan use this JSON metadata to request specific boxes and alert when a new version of a box is available.
- Beaker,
-
- Builds a single Vagrant box, without any version metadata.
- Requires you to manually provide a test directory and configuration files
-
Using
rake simp:packer:oldbuild- Takes a test directory that has the
vars.json,packer.yamlandsimp_conf.yamlalready set up like the old build process.
- Takes a test directory that has the
All methods are configured by environment variables and Rake task arguments.
IMPORTANT:
Packeruses around twice the space of the virtual image footprint when building, so ensure thatTMPDIRhas sufficient space. TMPDIRdefaults to/tmp` which is not (usually) large enough. This affects all methods.
Often, it is desirable to build several 'flavors' of simp-packer boxes at the
same time. A rake task, simp:packer:matrix has been provided for this purpose:
TMPDIR=/some/tmp/dir \
[ENV_VAR=value ...] \
bundle exec rake simp:packer:matrix[MATRIX_ELEMENTS ...]A typical example would look like:
TMPDIR="$PWD/tmp" \
MATRIX_LABEL=build_6.2.0RC1_ \
VAGRANT_BOX_DIR="$PATH_TO_VAGRANT_BOX_TREE" \
SIMP_ISO_JSON_FILES='${PATH_TO_ISO_JSON_FILES}/SIMP-6.2.0-0.el*.json' \
bundle exec rake simp:packer:matrix[os=el6:el7,fips=on:off]Assuming the glob ${PATH_TO_ISO_JSON_FILES}/SIMP-6.2.0-0.el*.json matched two
files (one for el6 and one for el7), this would result in four back-to-back
simp-packer builds:
- (
os=el6,fips=on) SIMP-6.2.0-0.el6 with FIPS mode enabled - (
os=el7,fips=on) SIMP-6.2.0-0.el7 with FIPS mode enabled - (
os=el6,fips=off) SIMP-6.2.0-0.el6 with FIPS mode disabled - (
os=el7,fips=off) SIMP-6.2.0-0.el7 with FIPS mode disabled
Build matrix elements are delimited by colons (:)
| Matrix args | Supported | Default | Description |
|---|---|---|---|
os= |
el6:el7 |
el6:el7 |
OSes to include in the matrix. JSON files will be filtered out if their data doesn't match one of these OSes. |
fips= |
on:off |
on |
Build SIMP Vagrant box with FIPS mode enabled |
encryption= |
on:off |
off |
Build SIMP Vagrant box with disk encryption |
firmware= |
bios:efi |
bios |
Defines which firmware base to use |
json= |
filepaths | N/A | (optional, if SIMP_ISO_JSON_FILES is set) List of absolute paths/globs to SIMP ISO .json files to consider |
NOTE: .json files (specified by json= and/or the environment variable
SIMP_ISO_JSON_FILES) are filtered based on whether their data matches the
os= matrix argument.
- If
os=el6and the glob${PATH_TO_ISO_JSON_FILES}/SIMP-6.2.0-0.el*.jsonmatched two files (one with data forel6and one forel7), only the file with data forel6would be included in the matrix (and theel7file would not be used). - If
os=el6:el7and the glob${PATH_TO_ISO_JSON_FILES}/SIMP-6.2.0-0.el*.jsonmatched two files (one with data forel6and one forel7), only the file with data forel6would be included in the matrix—and theel7file would not be used.
| Environment variable | Description |
|---|---|
VAGRANT_BOX_DIR |
Path to top of Vagrant box tree |
SIMP_ISO_JSON_FILES |
List of absolute paths/globs to SIMP ISO .json files to consider (delimiters: :, ,). This variable can be used as an alternative to the matrix entry json=. Non-existent paths will be discarded with a warning message |
MATRIX_LABEL |
Label for this matrix run that will prefix each iteration's directory name (default: build_<YYYYmmdd>_<HHMMSS>) |
TMPDIR=/some/tmp/dir \
[ENV_VAR=value ...] \
bundle exec rake simp:packer:build[vars_json,packer_yaml,simp_conf_yaml,test_dir]TMPDIR=/some/tmp/dir \
[ENV_VAR=value ...] \
bundle exec rake simp:packer:oldbuild[test_dir]The build version allows you to call using configuration files located from
other locations. You don't copy the config files to the test directory.
It will copy the files over for you but you have to type in all the locations.
The oldbuild versions allows you copy the files to a directory your self and run
just entering the directory.
- Both of these tasks create a single Vagrant box without version metadata.
Create a test directory, and include the following files:
vars.json: The JSON file that describes SIMP ISO. The simp-core taskrake build:autocreates a version of this file along with each SIMP ISO. It contains information like the ISO path, the ISO checksum, the name of the distribution ISO, and therootpassword. Samples can be found insamples/<sample>/vars.json.simp_conf.yaml: YAML generated bysimp config. You can use a copy of one from a previous build or edit one from fromsamples/<sample>/simp_conf.yaml. Puppet server and FIPS configurations will be overridden by settings from the build and matrix andpacker.yaml.packer.yaml: Overrides build defaults.simp-packerrequires this file (even if you don't want to override defaults). Samples can be found insamples/<sample>/packer.yaml. For CentOS 6 builds, you MUST change thenat_interfaceandhost_only_interfacetoeth0andeth1, respectively.
See samples/README.md for more information.
- A working directory will be created under the test directory, where all the scripts, manifests, and files are kept.
- A time-stamped log file is created in the top level of the test directory and
all the log output from
packeris copied there. If thepackerbuild fails, it is renamed from<date>.logto<date>.log.errors. - A Vagrant box file (
*.box) with itsVagrantfileandVagrantfile.erbwill be located in the directory defined by thepacker.yaml fileoutput_directory(default is<testdirectory>/OUTPUT).
- The Environment Variables for Packer are useful to customize builds.
- Other important variables:
| Variable | Description |
|---|---|
TMPDIR |
This is a POSIX environment variable that is often critical to set when running packer: the directory must be able to store over 4GB as the box is being built. The default location is /tmp, which on many systems is unable to store that much data. |
EXTRA_SIMP_PACKER_ARGS |
Extra CLI arguments when running packer build |
SIMP_PACKER_verbose |
When yes, some simp-packer logic produces more detailed output (default: no). |
./
├── assets/ ................ Images used by README.md
├── lib/ Ruby libraries
├── puppet/ ‡Puppet code (run inside VM)
│ └── modules/ ‡ contains `simpsetup::`
├── rakelib/ ............... Rake tasks
├── samples/
│ └── README.md
├── scripts/................ ‡ Shell scripts (run inside VM)
│ ├── config/ ‡ scripts that configure the VM
│ ├── tests/ ‡ VM tests
├── templates/.............. Templates
│ ├── simp.json.erb Annotated JSON Packer template in ERB format
│ ├── simp.json/ Directory of sub templates for simp.json file
│ ├── Vagrantfile.erb Vagrantfile generated along with `.box` files
│ └── Vagrantfile.erb.erb Vagrantfile.erb (for `vagrant init --template`)
└── README.md
‡ = Executed inside VMs as simp-packer is building them
The packer file is generated from the file `templates/simp.json.erb and settings from the packer.yaml file.
- Installs the ISO
- Adds the
vagrantuser - Sets umask for
root - Configures the network to start up a boot time
- Changes the passwords for
simpandroot - Updates the
sudoersfile sosimpuser can sudo without a password and without a tty
Runs a suite of configurations and tests while packer is provisioning the new box:
Configurations:
- Checks that FIPS was enabled/disabled per configuration.
- Runs
simp configandsimp bootstrap. - Installs a manifest that configures the
vagrantuser so you canvagrant sshonce the box is built, configuressimpuser sopackercan continue working - Reboots and runs Puppet a couple of times.
Tests:
- Ensures that the build of the puppetserver is successful and the puppetserver
is up and running and listening on the ports configured in
simp_conf.yaml. - Verifies that FIPS is setting match across the
simp_conf.yaml, thesimp_config_settings.yamland the operational environment. - Checks that selinux is set to
enforcing(the default for simp.) - If
simp_crypt_diskis used in thesimp.conf, it verifies that the disk is encrypted. - Verifies that
/,/var/,/var/auditare separate partitions. - Checks that the port in
puppet.conffile matches the port insimp_conf.yaml
After the tests pass, simp-packer configures the Puppet by running puppet apply on the simpsetup module is applied using puppet apply. It is run
once so that if you make changes later on they are not overwritten. This module
does the following:
- Sets up the kickstart files
- Sets up DNS
- Sets up TFTP manifests
- Runs the FakeCA
togenscript to generate SIMP application certificates for the SIMP server and all the clients pre-configured in DHCP and DNS. - Adds users and groups into LDAP
- Sets up autosign to be
*.<domain name>, so kickstarted systems will get their Puppet certificates autosigned. - Runs scripts that edit the
site.ppfile to create some hostgroups and the SIMP server's hiera file to include kickstart and tftpboot classes. - Copies into the
sitemodule, but does not use, other useful manifests site such asworkstation.ppandnfs.pp. These manifests will be refined as the test suite is expanded. - Runs puppet once more
The post-processor then exports the VirtualBox to a Vagrant box and removes the output directory.
- The
vagrantuser's SSH password isvagrant. - The Vagrantfile is not wrapped in the Vagrant
.box, so the network settings can be seen. Vagrant is not easily configured to check if a vbox hostonly network exists; you will have to ensure the network exists before runningvagrant up. - You can change the network name in the Vagrant file.
- The Vagrantfile does not configure the machine to use its IP address. You can turn it on, but changing the IP address will mess up the puppet server.
- Synced folders are disabled.
- The Puppet server's IP will be
X.X.X.7 - DHCP and DNS are pre-populated with entries for
server21.domain.namethroughserver29.domain.name, andws31.domain.nametows39.domain.name.- Each host's IP and MAC will match the hostname's number: e.g.,
server21will have the IPX.X.X.21and the MAC addressXX:XX:XX:XX:XX:21.
- Each host's IP and MAC will match the hostname's number: e.g.,
- The default password for the
rootandsimpuser accounts isP@ssw0rdP@ssw0rd.- You can override this in
vars.jsonby settingnew_password. - At this time, there is no mechanism to change the LDAP Password.
- You can override this in
- The SIMP server is configured to be an LDAP server:
- The
basednwill match thepacker.yaml'sdomain(or use the default). - Basic LDAP users are included:
user1,user2,admin1,admin2admin1andadmin2are in theadministratorsgroup.
- The
- The default distribution's ISO path is
/net/ISO/Distribution_ISOs. This is currently hard-coded insimp.json.erb.
This error is generally encountered during the OS ISO upload, and it means what it says: the host machine that is building the VM has run out of available RAM
Characteristic log snippet:
2018/08/13 15:38:35 ui: ==> virtualbox-iso: Uploading /path/to/ISO/CentOS-7-x86_64-DVD-1708.iso => /var/local/simp/CentOS-7-x86
_64-DVD-1708.iso
==> virtualbox-iso: Uploading /path/to/ISO/CentOS-7-x86_64-DVD-1708.iso => /var/local/simp/CentOS-7-x86_64-DVD-1708.iso
2018/08/13 15:38:35 packer: 2018/08/13 15:38:35 [DEBUG] Opening new ssh session
2018/08/13 15:38:35 packer: 2018/08/13 15:38:35 [DEBUG] Starting remote scp process: scp -vt /var/local/simp
2018/08/13 15:38:35 packer: 2018/08/13 15:38:35 [DEBUG] Started SCP session, beginning transfers...
2018/08/13 15:38:35 packer: 2018/08/13 15:38:35 [DEBUG] scp: Uploading CentOS-7-x86_64-DVD-1708.iso: perms=C0600 size=4521459712
2018/08/13 15:38:43 packer: fatal error: runtime: out of memory
2018/08/13 15:38:43 packer:
2018/08/13 15:38:43 packer: runtime stack:
2018/08/13 15:38:43 packer: runtime.throw(0x2314ecc, 0x16)
2018/08/13 15:38:43 packer: /usr/local/go/src/runtime/panic.go:616 +0x81
simp_config.rb configures the vagrant post-processor to write the .box file
into the <testingdirectory>/OUTPUT directory, or the path of
output_directory if it is defined by the packer.yaml file. If this
location does not have the capacity to hold the box while it is being
constructed, it will fail.
Characteristic log snippet:
==> virtualbox-iso: Running post-processor: vagrant
==> virtualbox-iso (vagrant): Creating Vagrant box for 'virtualbox' provider
virtualbox-iso (vagrant): Copying from artifact: OUTPUT/packer-virtualbox-iso-1454117110-disk1.vmdk
Build 'virtualbox-iso' errored: 1 error(s) occurred:
* Post-processor failed: write /tmp/packer040362584/packer-virtualbox-iso-1454117110-disk1.vmdk: no space left on device
==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: 1 error(s) occurred:
* Post-processor failed: write /tmp/packer040362584/packer-virtualbox-iso-1454117110-disk1.vmdk: no space left on device
==> Builds finished but no artifacts were created.
Please read our Contribution Guide.
If you find any issues, they can be submitted to our JIRA.
To see a list of development-related tasks available for this project, run:
bundle exec rake -T
Validation:
- Ruby code is linted with rubocop, using
bundle exec rake test:rubocup. - Shell scripts are linted with shellcheck, using
bundle exec test:shellcheck.- (The
shellcheckbinary is is now built into Travis CI environments, even forlanguage: ruby!) - NOTE: The version of
shellcheckon Travis CI may be different than your local development environment. In particular, the EL7 EPELShellCheckpackage is much older (0.35 vs 0.45+)—in practice, this has generally meant thatshellcheckin Travis CI catches more nuanced errors.
- (The
- Puppet code and metadata is linted as part of the
test:puppetrake task. At the moment, only Puppet code underpuppet/modules/is linted.
Puppet (SIMP versions):
- All Puppet modules under the
puppet/modules/directory will be tested usingbundle exec rake test:puppet. - The Travis CI pipeline matrix only considers the versions of Puppet used in SIMP along with the latest 5.x (which is informational, and allowed to fail).
simp-packer is intended to create a family of different SIMP box configurations to support automated integration tests for the entire SIMP Pre-Release checklist (requires SIMP-5238):
The following family of box roles can be used to automate integration tests for an ISO-based SIMP release:
-
simp-server— a freshly-installed SIMP server, withsimp configandsimp bootstrapalready applied -
simp-server-noconfig— a freshly-installsimp-server, but before runningsimp config -
empty— a completely empty vagrant box, used to test PXE boots and kickstarts -
simp-client— a pre-seeded SIMP client -
simp-wsclient— a pre-seeded SIMP workstation client -
linux-min— a SIMP installation using thelinux-minboot option
Non-ISO installations can be also be configured and tested, and they would be
able to re-use most of the Beaker suites designed for use with the
simp-server box role in simp-integration_tests.
- Alternative
simp-serverboxes:-
yumbuilt-simp-server— a freshly-installed SIMP server, built from a fresh OS install using the Installing SIMP From A Repository procedure. -
r10kbuilt-simp-server— a freshly-installed SIMP server, built from a fresh OS install using the r10k/Code Manager Installation procedure.
-
- Verify documentation
- Environment Variables
- The purpose of simp-packer
- Contribution/Development
- Roadmap
- Asset tests (phase 1—low-hanging fruit):
- Shellcheck to lint shell scripts
- Rubocop to lint ruby scripts
- Local Puppet module tests: syntax validation, lint checks, and spec
- All asset tests should be run from rake tasks
- Update the Travis CI pipeline to run asset tests
- Asset tests (phase 2—more complete):
- Tests (at least linting) for any non-module puppet manifests?
- Validate
simp.json.erbcreates a parseable JSON file - Validate
simp.jsonusing the packer JSON schema - Spec tests for ruby code (after refactoring into testable components)
under
lib/) - Update the GitLab CI pipeline to run asset tests
test:shellcheckwill need ashellcheck-capable CI Runner
- Integration tests during
packer build:- Test if the SIMP server's YUM repos are setup and working. These are the repos the SIMP clients are configured to use.
- Check if puppet is actually running on the port you specified using
netstatorss. - Add one last puppet run in at the end and check that it returns 0. Since all services including DNS should be set up, nothing should change at that point.)
- Compose
simp-packer.jsonfrom JSON snippets (SIMP-5238) - Move the packer build into a rake task
- Support move to Hiera 5 when building SIMP 6.3+ boxes:
- New system installs for SIMP >= 6.3+ use Hiera 5
- New system installs for SIMP <= 6.2.x must still use Hiera 3
-
simp:packer:matrixmatrix build - Refactor reusable host-side ruby code into a
lib/directory - Add an Environment variable in to allow it to create the box, even if tests fail.
- Kickstart a client to go with the box (see: Box roles)
- Make the location of the distribution ISO configurable.
Right now it is hard-coded to be(Now provided by/net/ISO/Distribution_ISOsvars.json>iso_url) - Validate input from
packer.yaml - Don't fail if
packer.yamldoesn't exist (it should be able to run with all the defaults). - Save version metadata for a
.boxfile in Vagrant Cloud API format (rake vagrant:json) - Scaffold and maintain a local Vagrant box directory tree of
.boxand.jsonversion metadata files. The.jsonfiles must be consumable by localvagrant initandvagrant upcommands.-
Scaffold tree(rake vagrant:publish:local) -
Add boxes to tree(rake vagrant:publish:local) - Remove boxes from tree
-
List boxes in tree(rake vagrant:tree:list) - Find/search boxes in tree
- Refresh top-level box metadata to include all versions of each box
- Prune older box versions from tree
-
- Restructure project to place puppet code in one place, ruby another, etc
- ruby
- rake tasks
- simp_config.rb
- puppet
- modules
- right now some Puppet code is embedded as bash heredocs
- ruby
- Change the
packer.yamlsettings to match the names used in thesimp.jsonfile to make things more consistent and will allow code simplification. - Merge the
simp_config.rbandsimp_packer_tests.shinto one ruby script and clean it up. - Delete the Virtualbox host-only network if we created it
-
rake cleanshould delete symlinks that will break packer. - Fix builds from SIMP-6.1.0-0 ISOs

