20.04.2. 使用 cloud-init 文件的 runcmd 运行复制等基本命令以及执行 shell 脚本

20.04.2. 使用 cloud-init 文件的 runcmd 运行复制等基本命令以及执行 shell 脚本

#cloud-config

autoinstall:
  apt:
    geoip: true
    preserve_sources_list: false
    primary:
    - arches: [amd64, i386]
      uri: http://us.archive.ubuntu.com/ubuntu
    - arches: [default]
      uri: http://ports.ubuntu.com/ubuntu-ports
  identity: {hostname: ubuntu-autoinstall, password: "$6$exDY1mhS4KUYCE/2$zmn9ToZsTKLGmw.b4/b.Z2TIZM20JC4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/y1bJ1f8wxED22bTL4F46P0", username: ubuntu, realname: ubuntu}
  keyboard: {layout: us, toggle: 'null', variant: ''}
  locale: en_US

  # Network interface configuration. Interface name device-specific. Requires modification.
  # Network is nested twice per new autoinstall layout.
  network:
    network:
      version: 2
      renderer: networkd
      ethernets:
        enp3s0: {dhcp4: true}

  # SSH configuration along with keys go here. 
  ssh:
    allow-pw: true
    authorized-keys: []
    install-server: true

  storage:
    config:
    - {ptable: gpt, path: /dev/sda,
      wipe: superblock, preserve: false, name: '', grub_device: false, type: disk,
      id: disk-sda}
    - {device: disk-sda, size: 536870912, wipe: superblock, flag: boot, number: 1,
      preserve: false, grub_device: true, type: partition, id: partition-0}
    - {fstype: fat32, volume: partition-0, preserve: false, type: format, id: format-0}
    - {device: disk-sda, size: 1073741824, wipe: superblock, flag: '', number: 2,
      preserve: false, type: partition, id: partition-1}
    - {fstype: ext4, volume: partition-1, preserve: false, type: format, id: format-1}
    - {device: disk-sda, size: 62410194944, wipe: superblock, flag: '', number: 3,
      preserve: false, type: partition, id: partition-2}
    - name: ubuntu-vg
      devices: [partition-2]
      preserve: false
      type: lvm_volgroup
      id: lvm_volgroup-0
    - {name: ubuntu-lv, volgroup: lvm_volgroup-0, size: 31195136000B, preserve: false,
      type: lvm_partition, id: lvm_partition-0}
    - {fstype: ext4, volume: lvm_partition-0, preserve: false, type: format, id: format-2}
    - {device: format-2, path: /, type: mount, id: mount-2}
    - {device: format-1, path: /boot, type: mount, id: mount-1}
    - {device: format-0, path: /boot/efi, type: mount, id: mount-0}
  version: 1

  cloud_config_modules:
    - runcmd

  cloud_final_modules:
    - scripts-user

  runcmd:
    - [mkdir, nettools]
    - [cp, -r,  /media/cdrom/files/, nettools/]
    - [sh, /nettools/files/setup.sh]
 

setup.sh在使用 下的命令成功自动安装后,我无法运行脚本文件 ( ) runcmd:。该setup.sh文件位于 pen-drive 上,需要复制到系统上才能运行。请帮助我了解我哪里出错了以及如何解决错误。我的假设可能是我在 下列出的命令的语法有误runcmd:。如果可能的话,我还想了解在安装后运行 shell 脚本的其他方法。

感谢您的时间!

相关内容