Search code examples
cloud-init

How to execute command in cloud-init


my cloud-init file looks like this I want to append random 1-byte hexa

#cloud-config
runcmd:
  - [ sudo, ip, link, set, dev, enp1s0, address, f4:f2:c7:f3:f4:"$(openssl rand -hex 1)" ]

no issue if i set static 6 bytes hexa like below

  - [ sudo, ip, link, set, dev, enp1s0, address, f4:f2:c7:f3:f4:c6 ]

Solution

  • runcmd doesn't require every argument to be in a list.

    Something like this should work:

    #cloud-config
    runcmd:
      - sudo ip link set dev enp1s0 address f4:f2:c7:f3:f4:"$(openssl rand -hex 1)"