2

I deploy a VM using an ansible playbook, similar to this demo.

- name: Create VM
  azure_rm_virtualmachine:
    resource_group: myResourceGroup
    name: myVM
    ...
    custom_data: cloud-init.yml

Now I also want to install some packages and do some minor preparations. I made a cloud-config.yml

#cloud-config

package_upgrade: true
packages:
  - npm
  - nodejs-legacy

runcmd:
- sudo mkdir -p /data/projects/

It seems that cloud-init.yml is not executed, so I guess this is not the correct syntax. How should you pass cloud-init files in an ansible playbook? Or is there another method to reach this goal?

Roelant
  • 4,508
  • 1
  • 32
  • 62

1 Answers1

1

custom_data parameter in azure_rm_virtualmachine requires the data, not a filename.

You can use file lookup plugin to fetch the data from a file on an Ansible controller:

- name: Create VM
  azure_rm_virtualmachine:
    resource_group: myResourceGroup
    name: myVM
    ...
    custom_data: "{{ lookup('file', 'cloud-init.yml') }}"
techraf
  • 64,883
  • 27
  • 193
  • 198