How to a cloud-config script copy a file to a server

cloud-configcloud-init

How can a cloud-config script copy a file to a server? write_files requires the file content in the script. How can I specify an external file that contains the content?

Best Answer

You haven't given enough context to know for sure, but for the purposes of this answer I'll assume you're running in Amazon Web Services.


As per the cloud-init documentation here, the only way to create a file directly via cloud-init is to include the file content in the script, either raw, base64-encoded, gzipped or base-64+gzipped.

Apart from doing that, the most straightforward way to do this would be to download the file - either via HTTP or an API call (for example, to S3).

Another way of getting the file onto the server would be to create a custom OS image (AMI) containing the file, by using something like Packer.

Related Topic