2

I'm using Packer 0.9.0 and as post-processor "shell-local" to run one script. The problem is that the shell script run for each artifacts generated (.vmdk, .vmx, etc.) and I don't know the reason.

The source code:

{
    "variables": {
        "root_password": "pass",
        "output_directory": "output/centos6-aufs-master-slave-vmw"
    },
    "builders": [
        {
            "type": "vmware-iso",
            "name": "centos6-aufs-master-slave-vmw",

            "iso_url": "http://myrepo/software/isos/CentOS-6.5-x86_64-minimal.iso",
            "iso_checksum": "ee3c7e96ad0a33d8af787acbf6d54e56",
            "iso_checksum_type": "md5",

            "ssh_username": "root",
            "ssh_password": "{{user `root_password`}}",
            "ssh_port": 22,
            "ssh_wait_timeout": "10000s",

            "shutdown_command": "shutdown -P now",
            "boot_command": [
                "<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/al-master-slave-ks.cfg<enter><wait>"
            ],

            "boot_wait": "10s",

            "disk_size": 51200,
            "disk_type_id": "0",

            "format": "ovf",

            "guest_os_type": "rhel6-64",
            "tools_upload_flavor": "linux",

            "http_directory": "http",

            "output_directory": "{{user `output_directory`}}",

            "vmx_data": {
                "memsize": "2048",
                "numvcpus": "1",
                "cpuid.coresPerSocket": "1"
            }
        }
    ],
    "post-processors": [
        {
            "type": "shell-local",
            "only": ["centos6-aufs-master-slave"],
            "inline": ["cd scripts","./vmx-to-ova.sh"],
            "environment_vars": ["PACKER_OUTPUT_DIRECTORY=/home/myuser/projects/IT/packer-project/output/centos6-aufs-master-slave-vmw"]
        }
    ]
}
enrique-carbonell
  • 5,836
  • 3
  • 30
  • 44

1 Answers1

1

Your post-processor will run once per artifact. Use artifice post-processor to override the artifact list forcing the shell-local post-processor to use the selected artifact. For example:

"post-processors": [
  [
    {
      "type": "artifice",
      "only": ["centos6-aufs-master-slave-vmw"],
      "files": ["{{user `output_vmw_directory`}}/centos6-aufs-master-slave-vmw.vmx"]
    },
    {
      "type": "shell-local",
      "only": ["centos6-aufs-master-slave-vmw"],
      "scripts": [
        "scripts/vmx-to-ova.sh"
      ],
      "environment_vars": ["PACKER_OUTPUT_DIRECTORY=/home/myuser/projects/IT/packer-project/centos6-aufs-master-slave/{{user `output_vmw_directory`}}"]
    }
  ]
]

The doc: https://www.packer.io/docs/post-processors/artifice.html

jcgomezcorrea
  • 51
  • 1
  • 3