How to get customData to correctly pass base64 encoded string in Azure ARM template

Hi,

I am trying to pass a string from a powershell script, to an ARM template, and use that string in the customData part of the osProfile object in the template.

Passing the string directly as such:

"customData": "[base64('#cloud-confignpackage_upgrade: truenpackages:n - htopn - unzipn - lsscsi')]" 

works just the way I want it to.

However, when I pass this string

'#cloud-confignpackage_upgrade: truenpackages:n - htopn - unzipn - lsscsi' 

from PowerShell to a parameter in the template, and then passing that parameter as such to the osProfile.customData attribute like:

"customData": "[base64(parameters('customData')]" 

it doesn’t work.

I have also tried creating a variable that base64 encodes the string passed to parameter like:

"customData": "[base64('parameters('customData')]" 

and then passing the variable to the osProfile.customData like:

"customData": "[variables('customData')]" 

and still an error.

I think this is the relevant error, because it is in the cloud-init.log of the VM that doesn’t use the direct mapping of the string to the customData in osProfile:

2019-08-14 18:08:06,879 - __init__.py[DEBUG]: Calling handler CloudConfigPartHandler: [['text/cloud-config', 'text/cloud-config-jsonp']] (__begin__, None, 3) with frequency once-per-instance 2019-08-14 18:08:06,879 - __init__.py[DEBUG]: Calling handler ShellScriptPartHandler: [['text/x-shellscript']] (__begin__, None, 2) with frequency once-per-instance 2019-08-14 18:08:06,879 - __init__.py[DEBUG]: Calling handler BootHookPartHandler: [['text/cloud-boothook']] (__begin__, None, 2) with frequency once-per-instance 2019-08-14 18:08:06,879 - __init__.py[DEBUG]: Calling handler UpstartJobPartHandler: [['text/upstart-job']] (__begin__, None, 2) with frequency once-per-instance 2019-08-14 18:08:06,879 - __init__.py[DEBUG]: Calling handler JinjaTemplatePartHandler: [['text/jinja2']] (__begin__, None, 3) with frequency once-per-instance 2019-08-14 18:08:06,879 - __init__.py[DEBUG]: {'MIME-Version': '1.0', 'Content-Type': 'text/cloud-config', 'Content-Disposition': 'attachment; filename="part-001"'} 2019-08-14 18:08:06,879 - __init__.py[DEBUG]: Calling handler CloudConfigPartHandler: [['text/cloud-config', 'text/cloud-config-jsonp']] (text/cloud-config, part-001, 3) with frequency once-per-instance 2019-08-14 18:08:06,880 - util.py[DEBUG]: Attempting to load yaml from string of length 80 with allowed root types (<class 'dict'>,) 2019-08-14 18:08:06,880 - util.py[DEBUG]: loaded blob returned None, returning default. 2019-08-14 18:08:06,880 - util.py[WARNING]: Failed at merging in cloud config part from part-001 2019-08-14 18:08:06,880 - util.py[DEBUG]: Failed at merging in cloud config part from part-001 Traceback (most recent call last): File "/usr/lib/python3/dist-packages/cloudinit/handlers/cloud_config.py", line 139, in handle_part self._merge_part(payload, headers) File "/usr/lib/python3/dist-packages/cloudinit/handlers/cloud_config.py", line 115, in _merge_part (payload_yaml, my_mergers) = self._extract_mergers(payload, headers) File "/usr/lib/python3/dist-packages/cloudinit/handlers/cloud_config.py", line 94, in _extract_mergers mergers_yaml = mergers.dict_extract_mergers(payload_yaml) File "/usr/lib/python3/dist-packages/cloudinit/mergers/__init__.py", line 83, in dict_extract_mergers raw_mergers = config.pop('merge_how', None) AttributeError: 'NoneType' object has no attribute 'pop' 

Any ideas? I’m at a loss as to what else to do.

submitted by /u/deathcat5
[link] [comments]

Leave a Reply