I'm struggling with the character encoding for user-data.
I try to submit the user-data in a here-string:
$userData = @"
#cloud-config
users:
- name: ubuntu
groups: docker
"@
then I convert the string and set the ova value:
$ovaConfig.Common.user_data.Value = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($userData))
If I deploy the VM the user-data seems to be in a wrong format, I get a error in cloud-init-output.log :
2020-06-08 12:40:04,628 - util.py[WARNING]: Failed loading yaml blob. Invalid format at line 3 column 1: "while scanning a simple key
in "<unicode string>", line 3, column 1:
- name: ubuntu
^
could not find expected ':'
in "<unicode string>", line 4, column 1:
groups: docker
^"
The File "looks" ok:
head /var/lib/cloud/instance/user-data.txt
#cloud-config
users:
- name: ubuntu
groups: docker
I tried the same with reading the data from a windows text file and this works:
# get external user-data
$userData = Get-Content -Encoding UTF8 -raw .\user-data.txt
# encode and set user-data
$ovaConfig.Common.user_data.Value = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($userData))
But not inline as explained above.
I suspect you might be hitting the strict syntax rules of YAML.
This Cloud config example show that you will need 2 blanks before the dash.
In my blog post Cloud-Init – Part 2 – Advanced Ubuntu you find another example
PS: I'm not a fan of these strict cloud init yaml rules :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I suspect you might be hitting the strict syntax rules of YAML.
This Cloud config example show that you will need 2 blanks before the dash.
In my blog post Cloud-Init – Part 2 – Advanced Ubuntu you find another example
PS: I'm not a fan of these strict cloud init yaml rules :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you, that was the issue. I was not aware of the two blanks rule.
You have really a good eye :smileylaugh:
Believe me, I was hit by this several times when I was doing that cloud init series :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference