在Packer配置器中添加条件?

时间:2015-07-24 18:28:07

标签: packer

是否有一种在包装商配置器中添加条件的明智方法?有什么影响:

$ packer build -var "debug=true" build.json


"provisioners": [{
  "type": "puppet-masterless",
  "execute_command": "{{ if eq `debug` "true" }} strace {{ end }} {{ .FacterVars }} puppet apply --verbose --detailed-exitcodes --modulepath='/tmp/manifests/modules' {{ .ManifestFile }}",
  "facter": {},
  "manifest_dir": "../manifests",
  "manifest_file": "../manifests/vagrant/nocm.pp",
  "module_paths": [
    "../manifests/modules/external"
  ]
}],
"variables": {
  "debug":    "false",
}

执行命令包含

{{ if eq `debug` "true" }} strace {{ end }}

1 个答案:

答案 0 :(得分:2)

您是否尝试在provisioner部分添加变量:

注意:我自己没有测试,但将其用于普通的shell配置程序

"provisioners": [{
  "environment_vars": [
    "DEBUG={{user `debug`}}",
  ]
  "type": "puppet-masterless",
  "execute_command": "{{ if eq .DEBUG "true" }} strace {{ end }} {{ .FacterVars }} puppet apply --verbose --detailed-exitcodes --modulepath='/tmp/manifests/modules' {{ .ManifestFile }}",
  "facter": {},
  "manifest_dir": "../manifests",
  "manifest_file": "../manifests/vagrant/nocm.pp",
  "module_paths": [
    "../manifests/modules/external"
  ]
}],
"variables": {
  "debug":    "false",
}