Skip to content

Instantly share code, notes, and snippets.

@jamtur01
Last active February 23, 2018 00:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamtur01/ca5eaf1e142e97d56e5bb171536b430a to your computer and use it in GitHub Desktop.
Save jamtur01/ca5eaf1e142e97d56e5bb171536b430a to your computer and use it in GitHub Desktop.
Running local Serverspec tests via Packer with thanks to Rickard von Essen
{
"variables": {
"aws_access_key": "",
"aws_secret_key": ""
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"source_ami": "ami-a025aeb6",
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "serverspec-ami {{timestamp | clean_ami_name}}"
}],
"provisioners": [{
"type": "shell",
"script": "install-puppet.sh"
},
{
"source": "hieradata",
"type": "file",
"destination": "/tmp"
},
{
"type": "puppet-masterless",
"manifest_file": "manifests/site.pp",
"puppet_bin_dir": "/opt/puppetlabs/bin",
"hiera_config_path": "hiera.yaml",
"module_paths": [
"modules"
]
},
{
"type": "shell",
"inline": [
"ifconfig enp0s5 | grep inet\\ | sed -e 's/.*inet \\([^ ]*\\).*/export TARGET_HOST=\\1/' > /tmp/ip"
]
},
{
"type": "file",
"source": "/tmp/ip",
"destination": "ip",
"direction": "download"
},
{
"command": ". ip && cd tests && echo $TARGET_HOST && rbenv exec rake spec",
"type": "shell-local"
}
]
}
require 'serverspec'
set :backend, :ssh
set :host, ENV['TARGET_HOST']
set :ssh_options, {
:password => 'vagrant',
:user => 'vagrant',
:paranoid => false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment