From 1f92aa2c0a8ded78488c33853477923023387bd4 Mon Sep 17 00:00:00 2001 From: Evan Machnic Date: Wed, 31 Jan 2018 10:49:04 -0600 Subject: [PATCH 1/4] Added Policyfile support to chef-client provisioner --- provisioner/chef-client/provisioner.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/provisioner/chef-client/provisioner.go b/provisioner/chef-client/provisioner.go index 7feab150c..51c315ca1 100644 --- a/provisioner/chef-client/provisioner.go +++ b/provisioner/chef-client/provisioner.go @@ -56,6 +56,8 @@ type Config struct { InstallCommand string `mapstructure:"install_command"` KnifeCommand string `mapstructure:"knife_command"` NodeName string `mapstructure:"node_name"` + PolicyGroup string `mapstructure:"policy_group"` + PolicyName string `mapstructure:"policy_name"` PreventSudo bool `mapstructure:"prevent_sudo"` RunList []string `mapstructure:"run_list"` ServerUrl string `mapstructure:"server_url"` @@ -82,6 +84,8 @@ type ConfigTemplate struct { ClientKey string EncryptedDataBagSecretPath string NodeName string + PolicyGroup string + PolicyName string ServerUrl string SslVerifyMode string TrustedCertsDir string @@ -270,6 +274,8 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { remoteValidationKeyPath, p.config.ValidationClientName, p.config.ChefEnvironment, + p.config.PolicyGroup, + p.config.PolicyName, p.config.SslVerifyMode, p.config.TrustedCertsDir) if err != nil { @@ -374,6 +380,8 @@ func (p *Provisioner) createConfig( ValidationKeyPath: remoteKeyPath, ValidationClientName: validationClientName, ChefEnvironment: chefEnvironment, + PolicyGroup: policyGroup, + PolicyName: policyName, SslVerifyMode: sslVerifyMode, TrustedCertsDir: trustedCertsDir, EncryptedDataBagSecretPath: encryptedDataBagSecretPath, @@ -688,6 +696,12 @@ node_name "{{.NodeName}}" {{if ne .ChefEnvironment ""}} environment "{{.ChefEnvironment}}" {{end}} +{{if ne .PolicyGroup ""}} +policy_group "{{.PolicyGroup}}" +{{end}} +{{if ne .PolicyName ""}} +policy_name "{{.PolicyName}}" +{{end}} {{if ne .SslVerifyMode ""}} ssl_verify_mode :{{.SslVerifyMode}} {{end}} From fe90f797041b7fe555bdbccc63818288b6a080c5 Mon Sep 17 00:00:00 2001 From: Evan Machnic Date: Wed, 31 Jan 2018 10:54:40 -0600 Subject: [PATCH 2/4] Changed new code to use tabs instead of spaces --- provisioner/chef-client/provisioner.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/provisioner/chef-client/provisioner.go b/provisioner/chef-client/provisioner.go index 51c315ca1..950bf7ea5 100644 --- a/provisioner/chef-client/provisioner.go +++ b/provisioner/chef-client/provisioner.go @@ -56,8 +56,8 @@ type Config struct { InstallCommand string `mapstructure:"install_command"` KnifeCommand string `mapstructure:"knife_command"` NodeName string `mapstructure:"node_name"` - PolicyGroup string `mapstructure:"policy_group"` - PolicyName string `mapstructure:"policy_name"` + PolicyGroup string `mapstructure:"policy_group"` + PolicyName string `mapstructure:"policy_name"` PreventSudo bool `mapstructure:"prevent_sudo"` RunList []string `mapstructure:"run_list"` ServerUrl string `mapstructure:"server_url"` @@ -84,8 +84,8 @@ type ConfigTemplate struct { ClientKey string EncryptedDataBagSecretPath string NodeName string - PolicyGroup string - PolicyName string + PolicyGroup string + PolicyName string ServerUrl string SslVerifyMode string TrustedCertsDir string @@ -274,8 +274,8 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { remoteValidationKeyPath, p.config.ValidationClientName, p.config.ChefEnvironment, - p.config.PolicyGroup, - p.config.PolicyName, + p.config.PolicyGroup, + p.config.PolicyName, p.config.SslVerifyMode, p.config.TrustedCertsDir) if err != nil { @@ -380,8 +380,8 @@ func (p *Provisioner) createConfig( ValidationKeyPath: remoteKeyPath, ValidationClientName: validationClientName, ChefEnvironment: chefEnvironment, - PolicyGroup: policyGroup, - PolicyName: policyName, + PolicyGroup: policyGroup, + PolicyName: policyName, SslVerifyMode: sslVerifyMode, TrustedCertsDir: trustedCertsDir, EncryptedDataBagSecretPath: encryptedDataBagSecretPath, From 735424793398d8c865459207426613087be21a05 Mon Sep 17 00:00:00 2001 From: Evan Machnic Date: Wed, 31 Jan 2018 11:01:08 -0600 Subject: [PATCH 3/4] Added policyGroup and policyName to Packer Communicator --- provisioner/chef-client/provisioner.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/provisioner/chef-client/provisioner.go b/provisioner/chef-client/provisioner.go index 950bf7ea5..b82bb939b 100644 --- a/provisioner/chef-client/provisioner.go +++ b/provisioner/chef-client/provisioner.go @@ -350,6 +350,8 @@ func (p *Provisioner) createConfig( remoteKeyPath string, validationClientName string, chefEnvironment string, + policyGroup string, + policyName string, sslVerifyMode string, trustedCertsDir string) (string, error) { From 5cedfc4557acea8043578ff3d6c8fba97cdbc575 Mon Sep 17 00:00:00 2001 From: Evan Machnic Date: Wed, 31 Jan 2018 11:06:31 -0600 Subject: [PATCH 4/4] Fixed go format errors --- provisioner/chef-client/provisioner.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/provisioner/chef-client/provisioner.go b/provisioner/chef-client/provisioner.go index b82bb939b..27d94c6c3 100644 --- a/provisioner/chef-client/provisioner.go +++ b/provisioner/chef-client/provisioner.go @@ -350,8 +350,8 @@ func (p *Provisioner) createConfig( remoteKeyPath string, validationClientName string, chefEnvironment string, - policyGroup string, - policyName string, + policyGroup string, + policyName string, sslVerifyMode string, trustedCertsDir string) (string, error) {