Find out if run through packer in cloudinit script

575 views
Skip to first unread message

Michael Seiwald

unread,
Mar 29, 2017, 7:55:37 AM3/29/17
to Packer
Hello,

I'm building an AMI that already includes a script that is supposed to be run on the first launch of the instance. My problem now is when someone wants to build a "child" AMI off of that AMI using my AMI as source_ami then my script will of course already run. I'm placing the script in /var/lib/cloud/scripts/per-once. Is there a way for me to determine inside the script if the instance was launched by packer? I was thinking about checking the Name tag on the instance for "Packer builder" but that can be overwritten. Is there an elegant way to solve this?

Thanks,
Michael

Rickard von Essen

unread,
Mar 29, 2017, 8:33:42 AM3/29/17
to packe...@googlegroups.com
Just put it in per-instance, then cloud-init will see to that it runes once per instance. 


Geschäftsführer: Pontus Noren, James Monico 
Sitz der Gesellschaft: München 
Amtsgericht München - HRB 212683 - USt-IdNr.: DE296631220


The above terms reflect a potential business arrangement, are provided solely as a basis for further discussion, 
and are not intended to be and do not constitute a legally binding obligation. No legally binding obligations 
will be created, implied, or inferred until an agreement in final form is executed in writing by all parties involved.

This email may be confidential or privileged. If you received this communication by mistake, please don't forward 
it to anyone else, please erase all copies and attachments, and please let us know that it has gone to the wrong person.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/425c66f4-368e-430a-b669-63139d29d75b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Seiwald

unread,
Mar 29, 2017, 8:42:47 AM3/29/17
to packe...@googlegroups.com
Thanks, I didn't know about per-instance. But still is there a way to make the script not run at all when launched by packer?

Cheers

On 29 March 2017 at 14:33, Rickard von Essen <rickard....@gmail.com> wrote:
Just put it in per-instance, then cloud-init will see to that it runes once per instance. 

You received this message because you are subscribed to a topic in the Google Groups "Packer" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/packer-tool/m3kkVteqvj8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CALz9Rt9fqdqT9BA64d-0vCBPT8x13XrHLAY%3DkbHrz1rcuZQYbg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Michael Seiwald
Cloud Systems Developer
 
 
Büro:  +49 89 381 535920 (x3408)


 
Cloudreach GmbH
Landsbergerstr. 300
80687 München
Deutschland

Rickard von Essen

unread,
Mar 29, 2017, 9:46:02 AM3/29/17
to packe...@googlegroups.com
No, unless you check for a specific aws tag, the username etc.

On Mar 29, 2017 2:42 PM, "Michael Seiwald" <michael...@cloudreach.com> wrote:
Thanks, I didn't know about per-instance. But still is there a way to make the script not run at all when launched by packer?

Cheers
On 29 March 2017 at 14:33, Rickard von Essen <rickard....@gmail.com> wrote:
Just put it in per-instance, then cloud-init will see to that it runes once per instance. 

Alvaro Miranda Aguilera

unread,
Apr 2, 2017, 7:17:12 AM4/2/17
to packe...@googlegroups.com
you can update your script to skip when packer variables are set:


  • PACKER_BUILD_NAME is set to the name of the build that Packer is running. This is most useful when Packer is making multiple builds and you want to distinguish them slightly from a common provisioning script.

  • PACKER_BUILDER_TYPE is the type of the builder that was used to create the machine that the script is running on. This is useful if you want to run only certain parts of the script on systems built with certain builders.


On Wed, Mar 29, 2017 at 2:42 PM, Michael Seiwald <michael...@cloudreach.com> wrote:
Thanks, I didn't know about per-instance. But still is there a way to make the script not run at all when launched by packer?

Cheers
On 29 March 2017 at 14:33, Rickard von Essen <rickard....@gmail.com> wrote:
Just put it in per-instance, then cloud-init will see to that it runes once per instance. 


For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Rickard von Essen

unread,
Apr 2, 2017, 11:46:18 AM4/2/17
to packe...@googlegroups.com
Just to be clear PACKER_BUILD_NAME and PACKER_BUILDER_TYPE won't be set in a cloud-init script. That only works for Packer provisioners.

// Rickard 

On 2 April 2017 at 13:17, Alvaro Miranda Aguilera <kik...@gmail.com> wrote:
you can update your script to skip when packer variables are set:


  • PACKER_BUILD_NAME is set to the name of the build that Packer is running. This is most useful when Packer is making multiple builds and you want to distinguish them slightly from a common provisioning script.

  • PACKER_BUILDER_TYPE is the type of the builder that was used to create the machine that the script is running on. This is useful if you want to run only certain parts of the script on systems built with certain builders.

Reply all
Reply to author
Forward
0 new messages