How to disable executing user-data by cloud-init

amazon ec2cloud-init

I am making a new AMI in EC2 and want to disable it running anything that could be put in user-data when launching (or rebooting) from this AMI. I looked at the existing /etc/cloud/cloud.cfg and /etc/cloud/cloud.cfg.d/* but do not see where this is enabled (so maybe it is on by default). How can I reconfigure cloud-init to not allow this or even allow this to be re-enbled? I suspect I also need to disable #cloud-config. Do I need to disable the whole cloud-init package to achieve this?

edit:

I will be using Amazon Linux and Ubuntu in various AMIs.

edit2:

It looks like I need to disable all of user-data. Maybe that will be easier.

edit3:

I do want to be able to access the user-data in my scripts.

Best Answer

This is my current hack — not too elegant, but it works:

patch /usr/lib/python2.7/dist-packages/cloudinit/stages.py <<EOF
@@ -469,7 +469,6 @@
     def consume_data(self, frequency=PER_INSTANCE):
         # Consume the userdata first, because we need want to let the part
         # handlers run first (for merging stuff)
-        self._consume_userdata(frequency)
         self._consume_vendordata(frequency)

         # Perform post-consumption adjustments so that
EOF