项目作者: shgtkshruch

项目描述 :
Building and testing Amazon Linux 2 and Vagrant Box with Packer, Ansible and Serverspec
高级语言: Ruby
项目地址: git://github.com/shgtkshruch/rails-packer-ansible-serverspec.git


Serverspec

Rails Packer Ansible Serverspec

Building and testing Amazon Linux 2 and Vagrant Box with Packer, Ansible and Serverspec.

Stacks

AWS

Install jq if you don’t have.

Create IAM user for Packer.

  1. $ ./aws/create-user.sh

Delete user.

  1. $ ./aws/delete-user.sh

Packer

Install

  1. $ brew tap hashicorp/tap
  2. $ brew install hashicorp/tap/packer
  3. $ packer --version
  4. 1.6.6

Build Image

  1. $ packer inspect packer/rails.json
  2. $ packer validate packer/rails.json
  3. $ export AWS_ACCESS_KEY_ID="anaccesskey"
  4. $ export AWS_SECRET_ACCESS_KEY="asecretkey"
  5. $ packer build packer/rails.json

Deregister Image

  1. $ aws ec2 deregister-image --image-id IMAGE_ID

Ansible

Install

  1. $ brew install ansible
  2. $ ansible --version
  3. ansible 2.10.4

Provisioning

  • Nginx
  • Ruby with rbenv
  • Node.js
  1. # Check playbook format
  2. $ ansible-playbook ansible/playbook.yml -i ansible/hosts --check

Vagrant

Install

  1. $ brew install vagrant
  2. $ vagrant --version
  3. Vagrant 2.2.14
  4. $ brew install virtualbox
  5. # https://stackoverflow.com/questions/52689672/virtualbox-ns-error-failure-0x80004005-macos
  6. $ vboxmanage --version
  7. 6.1.16r140961

Build Box

  1. $ packer build -force -only=vagrant packer/rails.json
  1. $ vagrant up
  2. $ vagrant ssh

Update Box

Add new version box configuration to packer/metadata.json, then run command below.

  1. $ vagrant box update

Serverspec

Install gems

  1. $ bundle install

Test

  1. $ bundle exec rake spec