my cloud-init is not getting passed to instance

RAKESH B R 0 Reputation points
2024-03-19T16:15:01.9633333+00:00

I Am using ARM template to create a VM .

I have added the cloud-init data in CustomData variable filed and encoded with base64 , which is being passed to instance ,

                "customData": "[concat('#cloud-config\ntimezone: ', parameters('TimeZone'), '\nmanage_resolv_conf: true\nresolv_conf:\n  nameservers: [\"', parameters('DnsServers'), '\"]\nntp:\n  enabled: true\n  ntp_client: chrony\n  config:\n     confpath: /etc/chrony.conf\n     check_exe: chronyd\n     packages:\n       - chrony\n     service_name: chronyd\n     template: |\n         ## template:jinja\n         # My NTP Client config\n         {%- if servers %}# servers\n         {% endif %}\n         {% for server in servers -%}\n         server {{server}} iburst\n         {% endfor %}\n  servers: [', parameters('NtpServers'), ']\nusers:\n- name: insight\n  ssh_authorized_keys:\n  - ', parameters('InsightSshKey'),'\n- name: admin\n  ssh_authorized_keys:\n  - ', parameters('AdminSshKey'), '\n\nwrite_files:\n  - path: ', variables('configFile'),'\n    content: |\n', variables('appConfigFileContent'), '\n')]"
        },

passed to VM

              {
                        "type": "Microsoft.Compute/virtualMachines",
                        "apiVersion": "2019-12-01",
                        "name": "[variables('vmName')]",
                        "location": "[parameters('location')]",
                        "dependsOn": [
                                "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]"
                        ],
                        "properties": {
                                "hardwareProfile": {
                                        "vmSize": "[parameters('vmSize')]"
                                },
                                "osProfile": {
                                        "computerName": "[variables('vmName')]",
                                        "adminUsername": "[variables('adminUsername')]",
                                        "customData": "[base64(variables('customData'))]",
                                        "linuxConfiguration": {
                                                "disablePasswordAuthentication": true,
                                                "ssh": {
                                                        "publicKeys": [{
                                                                "path": "[concat('/home/', variables('adminUsername'), '/.ssh/authorized_keys')]",
                                                                "keyData": "[parameters('AdminSshKey')]"
                                                        }]
                                                }
                                        }
                                },

cloud-init is failing in RHEL 8.9

in cloud-init error - isee

2024-03-18 14:39:44,177 - schema.py[WARNING]: Invalid cloud-config provided: Please run 'sudo cloud-init schema --system' to see the schema errors.

Cloud-init v. 23.1.1-11.el8_9.1 running 'modules:config' at Mon, 18 Mar 2024 14:39:44 +0000. Up 10693.83 seconds.

Cloud-init v. 23.1.1-11.el8_9.1 running 'modules:final' at Mon, 18 Mar 2024 14:39:45 +0000. Up 10694.47 seconds.

Cloud-init v. 23.1.1-11.el8_9.1 finished at Mon, 18 Mar 2024 14:39:45 +0000. Datasource DataSourceAzure [seed=IMDS]. Up 10694.67 seconds

[2024-03-18 14:39:45 root@Ribbon-RAMP-SA2: /home/admin ]# sudo cloud-init schema --system

Invalid cloud-config /var/lib/cloud/instances/70e4184e-9fb7-ed49-9238-cf864b50b577/cloud-config.txt

Error: Cloud config schema errors: format-l1.c1: File /var/lib/cloud/instances/70e4184e-9fb7-ed49-9238-cf864b50b577/cloud-config.txt needs to begin with "#cloud- config"

Error: Invalid cloud-config schema: user-data

once i run the suggested command from cloud-init , I see the file is empty

[2024-03-18 14:29:27 root@Ribbon-RAMP-SA2: /var/log ]# sudo cloud-init schema --system

Invalid cloud-config /var/lib/cloud/instances/70e4184e-9fb7-ed49-9238-cf864b50b577/cloud-config.txt

Error: Cloud config schema errors: format-l1.c1: File /var/lib/cloud/instances/70e4184e-9fb7-ed49-9238-cf864b50b577/cloud-config.txt needs to begin with "#cloud- config"

Error: Invalid cloud-config schema: user-data

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,094 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. deherman-MSFT 33,141 Reputation points Microsoft Employee
    2024-03-21T17:35:46.85+00:00

    @RAKESH B R Likely it is an issue with the format of the custom data. Is this working correctly when trying to deploy via Portal or CLI? It might be worth simplifying this by passing the cloud-init.txt directly using a method like this one.
    https://www.atmosera.com/blog/arm-templates-and-cloud-init/


    If you still have questions, please let us know in the "comments" and we would be happy to help you. Comment is the fastest way of notifying the experts.

    If the answer has been helpful, we appreciate hearing from you and would love to help others who may have the same question. Accepting answers helps increase visibility of this question for other members of the Microsoft Q&A community.

    Thank you for helping to improve Microsoft Q&A!

    User's image

    0 comments No comments