"Return" package provisioned version to Packer for tagging

I’m betting the answer to this is “no,” but maybe there’s a way I’m not seeing…
I have a Packer template that does a remote shell to install a current version of package (i.e., Jenkins)… I’d like to be able to “pull back” the installed version of that package, so I could annotate a tag on the new AMI with that version.

Is there a direct (or convoluted) way to do something like this? I saw the topic
Return variables from shell provisioner into packer variables but I don’t think it answers the question.

TIA -Alan

The thing I think isn’t directly possible here is to set the tag at provision time. We don’t re-interpolate tags after the provisioners run, and hadn’t considered the use case where you would need to set a new tag variable at runtime.

The way I used to do this at $LAST_JOB was to pin the version numbers as variables in my template before I ran Packer, so I had total control over what versions of packages were being added to my VM.

If you do want to be able to just install the latest version of a given package, then I think your best bet is to create a pre-flight script that wraps packer, checks for a package’s latest version, and then passes that version into Packer as a user variable you can set tags with.