Commit Graph

116 Commits

Author SHA1 Message Date
Megan Marsh b52143f528 update docs for command and make sure they get generated properly so they appear in the docs 2020-08-05 10:30:16 -07:00
Artem Zavatskiy bec367347d ansible-provisioner: fix tests related to ssh agent 2020-07-27 14:31:32 +03:00
Artem Zavatskiy c0048daed5 fix agent auth in ssh communicator for ansible provisioner (#9488) 2020-07-23 16:03:01 +03:00
Megan Marsh 8fc4e03139
quote packer build name to handle names with spaces (#9590) 2020-07-16 11:20:06 +02:00
Sylvia Moss 3dc7a53125
Correct check if PackerHttpAddr is implemented or not (#9498) 2020-06-29 16:17:21 +02:00
Megan Marsh b5b8f2e308
add template option for templating the inventory file lines (#9438) 2020-06-17 11:05:48 +02:00
Megan Marsh 3d7c9cb9c2
make ansible provisioner docs generated from code (#9439) 2020-06-17 10:09:03 +02:00
Lane, Larry 5976929595 Fix for #9283 2020-06-02 17:30:03 -05:00
Adrien Delorme 40947c2bf6
HCL2: generate hcl tags with go-cty tags too (#9306)
This will allow to generate the config files:

```go
package main

import (
	"fmt"

	"github.com/hashicorp/hcl/v2/gohcl"
	"github.com/hashicorp/hcl/v2/hclwrite"
	"github.com/hashicorp/packer/builder/alicloud/ecs"
)

func main() {
	name := "name"
	app := ecs.FlatConfig{
		AlicloudImageName: &name,
		ECSSystemDiskMapping: &ecs.FlatAlicloudDiskDevice{
			DiskName: &name,
		},
	}

	f := hclwrite.NewEmptyFile()
	block := gohcl.EncodeAsBlock(&app, `source "something" "something"`)
	f.Body().AppendBlock(block)
	fmt.Printf("%s", f.Bytes())
}

```

Will output:

```
source "something" "something" {
  packer_user_variables      = null
  packer_sensitive_variables = null
  image_name                 = "name"
  image_share_account        = null
  image_unshare_account      = null
  image_copy_regions         = null
  image_copy_names           = null
  tags                       = null
  tag                        = null
  system_disk_mapping        = { disk_category = null, disk_delete_with_instance = null, disk_descri
ption = null, disk_device = null, disk_encrypted = null, disk_name = "name", disk_size = null, disk_
snapshot_id = null }
  image_disk_mappings        = null
  ssh_remote_tunnels         = null
  ssh_local_tunnels          = null
  ssh_public_key             = null
  ssh_private_key            = null
}
```

This is a good first step for #9015 and #9282 

fix #9304
2020-05-28 11:19:00 +02:00
Lane, Larry f4254e9cbf updated test 2020-05-22 08:12:14 -05:00
Lane, Larry c689eb9694 added test 2020-05-22 08:07:25 -05:00
Lane, Larry de12432e6b add test 2020-05-22 07:58:57 -05:00
Lane, Larry e6670fc4a0 fix arg order 2020-05-21 21:15:13 -05:00
Sylvia Moss 1c30a71d09
Replace file shared state by statebag (#9238) 2020-05-19 11:49:48 +02:00
Adrien Delorme 840e67f775
HCL2: when we see a map generate an attribute spec instead of a block spec (#9035)
* mapstructure-to-hcl2: when we see a map generate an attribute spec and not a block spec

this will alow to do

tags = {
 key = "value"
}

instead of

tags {
  key = "value"
}

This will also enable using variables directly for those tags

* generate code

* update tests
2020-04-14 16:05:13 +02:00
Megan Marsh b66e49223d extract the building of command args into a testable helper function 2020-04-01 16:07:14 -07:00
Megan Marsh 91906b688c regenerate code 2020-04-01 11:37:25 -07:00
Megan Marsh 73c87044fd fix tests 2020-04-01 11:31:48 -07:00
Megan Marsh 64b706983e docs and cleanup 2020-04-01 11:31:48 -07:00
Megan Marsh d45ffe73d0 fix default ssh-extra-args flag 2020-04-01 11:31:48 -07:00
Megan Marsh d57809bcda pass ansible_password on command line instead of inside inventory file 2020-04-01 11:31:48 -07:00
Megan Marsh eda9ce70e7 update tests 2020-04-01 11:31:48 -07:00
Megan Marsh 9a40403433 clean up tests 2020-04-01 11:31:48 -07:00
Megan Marsh e155d2a1c8 add mock so we can test full provision flow 2020-04-01 11:31:48 -07:00
Megan Marsh 6c756a7b31 fix tests 2020-04-01 11:31:48 -07:00
Megan Marsh 19d49f8b78 templatize inventory files; implement inventory for winrm 2020-04-01 11:31:48 -07:00
Megan Marsh ca5814ab74 move proxy behind feature flag 2020-04-01 11:31:48 -07:00
Megan Marsh 4b9568e409 fix winrmpass sanitization to account for empty string value. 2020-01-06 10:07:30 -08:00
Adrien Delorme 4b7132c87c Merge remote-tracking branch 'origin/master' into sharing_info 2019-12-17 11:57:09 +01:00
Adrien Delorme 0785c2f6fc
build using HCL2 (#8423)
This follows #8232 which added the code to generate the code required to parse
HCL files for each packer component.

All old config files of packer will keep on working the same. Packer takes one
argument. When a directory is passed, all files in the folder with a name
ending with  “.pkr.hcl” or “.pkr.json” will be parsed using the HCL2 format.
When a file ending with “.pkr.hcl” or “.pkr.json” is passed it will be parsed
using the HCL2 format. For every other case; the old packer style will be used.

## 1. the hcl2template pkg can create a packer.Build from a set of HCL (v2) files

I had to make the packer.coreBuild (which is our one and only packer.Build ) a public struct with public fields

## 2. Components interfaces get a new ConfigSpec Method to read a file from an HCL file.

  This is a breaking change for packer plugins.

a packer component can be a: builder/provisioner/post-processor

each component interface now gets a `ConfigSpec() hcldec.ObjectSpec`
which allows packer to tell what is the layout of the hcl2 config meant
to configure that specific component.

This ObjectSpec is sent through the wire (RPC) and a cty.Value is now
sent through the already existing configuration entrypoints:

 Provisioner.Prepare(raws ...interface{}) error
 Builder.Prepare(raws ...interface{}) ([]string, error)
 PostProcessor.Configure(raws ...interface{}) error

close #1768


Example hcl files:

```hcl
// file amazon-ebs-kms-key/run.pkr.hcl
build {
    sources = [
        "source.amazon-ebs.first",
    ]

    provisioner "shell" {
        inline = [
            "sleep 5"
        ]
    }

    post-processor "shell-local" {
        inline = [
            "sleep 5"
        ]
    }
}

// amazon-ebs-kms-key/source.pkr.hcl

source "amazon-ebs" "first" {

    ami_name = "hcl2-test"
    region = "us-east-1"
    instance_type = "t2.micro"

    kms_key_id = "c729958f-c6ba-44cd-ab39-35ab68ce0a6c"
    encrypt_boot = true
    source_ami_filter {
        filters {
          virtualization-type = "hvm"
          name =  "amzn-ami-hvm-????.??.?.????????-x86_64-gp2"
          root-device-type = "ebs"
        }
        most_recent = true
        owners = ["amazon"]
    }
    launch_block_device_mappings {
        device_name = "/dev/xvda"
        volume_size = 20
        volume_type = "gp2"
        delete_on_termination = "true"
    }
    launch_block_device_mappings {
        device_name = "/dev/xvdf"
        volume_size = 500
        volume_type = "gp2"
        delete_on_termination = true
        encrypted = true
    }

    ami_regions = ["eu-central-1"]
    run_tags {
        Name = "packer-solr-something"
        stack-name = "DevOps Tools"
    }
    
    communicator = "ssh"
    ssh_pty = true
    ssh_username = "ec2-user"
    associate_public_ip_address = true
}
```
2019-12-17 11:25:56 +01:00
Megan Marsh 0f6d1beccf add an extra string array to the Prepare() return values in the builder interfaces; this sets up the ability for builders to give the provisioners custom user-accessible build-time variables. 2019-12-16 21:23:05 -08:00
Megan Marsh 82367a88f8 reorganize placeholder data call to live with provisioner implementation; force users to use the generated function, therefore forcing validation, for all variables except winrmpassword, by doing a simple string check against the placeholder data. 2019-12-14 03:32:38 -08:00
Megan Marsh 3389d843f0 update all provisioners that used the winrmpassword tooling to use the new generateddata option 2019-12-12 16:42:53 -08:00
Megan Marsh 39fd462b56 change all provision func signatures to use map[string]interface{} 2019-12-12 15:38:32 -08:00
Megan Marsh 0ca7c9f397 fix tests 2019-12-11 16:29:35 -08:00
Megan Marsh 6f418d0e54 get data sharing to a working state with the powershell provisioner 2019-12-11 15:43:38 -08:00
Megan Marsh f4c3501af5 pass struct of generated data into provision() call 2019-12-11 15:43:38 -08:00
Adrien Delorme 078ba7c8c3 commit old code generation tool
for history
2019-10-15 12:56:42 +02:00
Lars Lehtonen b207752883 provisioner/ansible: Fix dropped error 2019-08-27 16:52:52 -07:00
Ruben Tsirunyan 1b35c586ce Changes to roles_path option 2019-07-29 13:23:39 +04:00
Ruben Tsirunyan d247329599 Adding support for installing roles with ansible-galaxy for ansible provisioner 2019-07-29 13:23:39 +04:00
Megan Marsh 0f704fb5b2 These cancel functions have been obsolete since merge of c7ce4d598e 2019-07-26 14:12:58 -07:00
Megan Marsh 6dcff18d36 prevent nil pointer dereference by defining IsUserAuthority. This occurred as a regression when we updated the crypto library in v1.4.0 2019-06-11 13:43:13 -07:00
Adrien Delorme c7ce4d598e change Provisioner to be passed a context for cancellation 2019-04-03 15:55:54 +02:00
Adrien Delorme 5a6dffde9a use port as ints 2019-03-19 15:01:12 +01:00
xinau b449af84ee moved concurrency-safe ui code to packer/ui.go 2019-02-13 21:01:50 +00:00
xinau 36c1e8d838 moved adapter to common package 2019-02-12 07:10:57 +00:00
Rickard von Essen 52b55fb899
ansible: change local_port to uint instead of string 2019-02-04 18:47:42 +01:00
Adrien Delorme 9f7b4ffc17
Merge branch 'master' into pr/6950 2019-01-09 10:11:18 +01:00
mr-karan 01cdd18fd3 feat(provisioner/ansible): Provide extra SSH args
Adds `-o IdentitiesOnly=yes` as a default flag to extra vargs
in Ansible provisoner.

Closes https://github.com/hashicorp/packer/issues/5329
2018-12-14 19:07:54 +05:30