From a2277e312f497284f4c2d71fba57cf179f9a5654 Mon Sep 17 00:00:00 2001 From: Sylvia Moss Date: Thu, 13 Aug 2020 17:23:56 +0200 Subject: [PATCH] add inspec provisioner hcl2 examples (#9761) --- website/pages/docs/provisioners/ansible.mdx | 28 +++--- website/pages/docs/provisioners/inspec.mdx | 96 +++++++++++++++++++-- 2 files changed, 101 insertions(+), 23 deletions(-) diff --git a/website/pages/docs/provisioners/ansible.mdx b/website/pages/docs/provisioners/ansible.mdx index bfa50da3a..30db8601d 100644 --- a/website/pages/docs/provisioners/ansible.mdx +++ b/website/pages/docs/provisioners/ansible.mdx @@ -59,17 +59,17 @@ Example Packer template: ```hcl source "digitalocean" "example"{ - api_token = "6a561151587389c7cf8faa2d83e94150a4202da0e2bad34dd2bf236018ffaeeb" - image = "ubuntu-14-04-x64" - region = "sfo1" + api_token = "6a561151587389c7cf8faa2d83e94150a4202da0e2bad34dd2bf236018ffaeeb" + image = "ubuntu-14-04-x64" + region = "sfo1" } build { sources = [ - "source.digitalocean.example", + "source.digitalocean.example" ] - provisioner { - "playbook_file": "./playbook.yml" + provisioner "ansible" { + playbook_file = "./playbook.yml" } } ``` @@ -198,21 +198,21 @@ connection to chroot and running Ansible as root/sudo. ```hcl source "amazon-chroot" "example" { mount_path = "/mnt/packer-amazon-chroot" - region = "us-east-1" - source_ami = "ami-123456" + region = "us-east-1" + source_ami = "ami-123456" } build { sources = [ "source.amazon-chroot.example" ] - provisioner "ansible" { - extra_arguments = [ - "--connection=chroot", - "--inventory-file=/mnt/packer-amazon-chroot" - ] + provisioner "ansible" { + extra_arguments = [ + "--connection=chroot", + "--inventory-file=/mnt/packer-amazon-chroot" + ] playbook_file = "main.yml" - } + } } ``` diff --git a/website/pages/docs/provisioners/inspec.mdx b/website/pages/docs/provisioners/inspec.mdx index 94c576d67..233220972 100644 --- a/website/pages/docs/provisioners/inspec.mdx +++ b/website/pages/docs/provisioners/inspec.mdx @@ -21,6 +21,9 @@ by Packer. This is a fully functional template that will test an image on DigitalOcean. Replace the mock `api_token` value with your own. + + + ```json { "provisioners": [ @@ -41,6 +44,29 @@ Replace the mock `api_token` value with your own. } ``` + + + +```hcl +source "digitalocean" "example"{ + api_token = "" + image = "ubuntu-14-04-x64" + region = "sfo1" +} + +build { + sources = [ + "source.digitalocean.example" + ] + provisioner "inspec" { + profile = "https://github.com/dev-sec/linux-baseline" + } +} +``` + + + + ## Configuration Reference Required Parameters: @@ -52,19 +78,44 @@ Optional Parameters: - `inspec_env_vars` (array of strings) - Environment variables to set before running InSpec. Usage example: + + + ```json "inspec_env_vars": [ "FOO=bar" ] ``` + + + + ```hcl + inspec_env_vars = [ "FOO=bar" ] + ``` + + + + - `command` (string) - The command to invoke InSpec. Defaults to `inspec`. - `extra_arguments` (array of strings) - Extra arguments to pass to InSpec. These arguments _will not_ be passed through a shell and arguments should not be quoted. Usage example: + + + ```json "extra_arguments": [ "--sudo", "--reporter", "json" ] ``` + + + + ```hcl + extra_arguments = [ "--sudo", "--reporter", "json" ] + ``` + + + - `attributes` (array of strings) - Attribute Files used by InSpec which will be passed to the `--input-file` argument of the `inspec` command when this @@ -111,16 +162,32 @@ Optional Parameters: Chef InSpec requires accepting the license before starting to use the tool. This can be done via `inspec_env_vars` in the template: + + + ```json -"provisioners": [ - { - "type": "inspec", - "inspec_env_vars": [ "CHEF_LICENSE=accept"], - "profile": "https://github.com/dev-sec/linux-baseline" - } - ], + "provisioners": [ + { + "type": "inspec", + "inspec_env_vars": [ "CHEF_LICENSE=accept"], + "profile": "https://github.com/dev-sec/linux-baseline" + } + ] +``` + + + + +```hcl + provisioner "inspec" { + inspec_env_vars = [ "CHEF_LICENSE=accept"] + profile = "https://github.com/dev-sec/linux-baseline" + } ``` + + + See their [official docs](https://docs.chef.io/chef_license_accept/) to learn other ways to accept the license. ## Default Extra Variables @@ -143,8 +210,19 @@ commonly useful InSpec Attributes: To debug underlying issues with InSpec, add `"-l"` to `"extra_arguments"` to enable verbose logging. + + + ```json -{ "extra_arguments": ["-l", "debug"] -} ``` + + + + +```hcl + extra_arguments = ["-l", "debug"] +``` + + +