5

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?

Derek Mahar
  • 801
  • 2
  • 8
  • 15

2 Answers2

7

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.

Craig Watson
  • 9,370
  • 3
  • 30
  • 46
  • I'm using CoreOS, but my question refers to the `cloud-config` (or `cloud-init`) specification, not any particular implementation. I was wondering if there was some command that I had overlooked. It seems that `cloud-config` scripts are designed to pull, not push files to the target server. – Derek Mahar Jul 21 '16 at 20:50
  • 3
    It also strikes me that cloud-config scripts are meant only to bootstrap a server, not fully provision it. A provisioning tool like Ansible seems more appropriate for more sophisticated configuration. – Derek Mahar Jul 21 '16 at 21:02
0

scp in the runcmd section can retrieve files, albeit in the final stage of cloud-init.

Doug Reeder
  • 101
  • 2