1

I'm trying to set up a Ubuntu Server on Azure. None of the images do quite what I want, so I was planning on taking a vanilla Ubuntu image and using cloud-init to modify it. I'd like to be able to deploy this to multiple environments using Azure Pipelines and have an ARM Template that is deploying the vanilla instance quite nicely.

The issue I have is how to get the cloud-init script I have into the custom data parameter of the ARM Template. It seems that because ARM Templates have to be JSON the only way to do this is to have the cloud-init script on one very very long line. Either that or host the cloud-init file somewhere and do something hacky like this: https://www.wintellect.com/arm-templates-and-cloud-init/. The ARM Template task I'm using in Azure Pipelines does not seem to have a way to pass a file's contents as a parameter.

I'd like to have both the ARM Template and the cloud-init script as separate files in my private git repository. Currently I'm considering some kind of pre-processing build step to combine the two. Has anyone already done this and have a code example?

Maybe I'm "doing it wrong", what do other people do/what is the best way to do this?

1 Answer 1

1

I feel like you are providing the answer yourself. Encode the entire cloud-init file as one-line base64 using a pre-processing script. Something like cat cloud-init.txt | base64 -w0 would work for Linux based build agents, -w0 will encode everything in one line.

1
  • This is basically what I ended up doing, only I used PowerShell. I was hoping that there was some way to simply specify the file name and have the encoding part done for me. $encodedContent = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($cloudInitContent )) Commented Jun 12, 2021 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.