{
  "description"               : "Pull Ubuntu16 cloud image and build seed CDROM iso",
  "prerequisiteGraphUri"      : "prep-ubuntu16-cloud-init-01.json",
  "options"                   : {
    "displayExecutionGraphDescription": true
  },
  "asynchronousCommands"      : [
    {
      "description"                : "Write stub 'seed' file",
      "suppressOutput"             : false,
      "suppressDiagnostics": true,
      "showPreAndPostSpawnMessages": true,
      "outputColor"                : "",
      "useSudo"                    : false,
      "command"                    : "bash",
      "suppressFinalError"         : true,
      "args"                       : [
        "-c",
        "[[ ! -f \"$HOME/ubuntu-cloud-init/seed\" ]] && echo \"#cloud-config\npassword: password\nchpasswd: { expire: False }\nssh_pwauth: True\" > \"$HOME/ubuntu-cloud-init/seed\""
      ]
    },
    {
      "description"                : "Create '_build_seed_img.sh' to build cdrom boot image",
      "suppressOutput"             : false,
      "suppressDiagnostics": true,
      "showPreAndPostSpawnMessages": true,
      "outputColor"                : "",
      "useSudo"                    : false,
      "command"                    : "bash",
      "suppressFinalError"         : true,
      "args"                       : [
        "-c",
        "[[ ! -f \"$HOME/ubuntu-cloud-init/_build_seed_img.sh\" ]] && echo \"#!/usr/bin/env bash\ncloud-localds seed.img seed\" > \"$HOME/ubuntu-cloud-init/_build_seed_img.sh\""
      ]
    },
    {
      "description"                : "Create '_scp_config_to_qemu_machine.sh' to get the config script in the VM",
      "suppressOutput"             : false,
      "suppressDiagnostics": true,
      "showPreAndPostSpawnMessages": true,
      "outputColor"                : "",
      "useSudo"                    : false,
      "command"                    : "bash",
      "suppressFinalError"         : true,
      "args"                       : [
        "-c",
        "[[ ! -f \"$HOME/ubuntu-cloud-init/_scp_config_to_qemu_machine.sh\" ]] && echo \"#!/usr/bin/env bash\nsudo scp -P 5555 _mount_qnap.sh _config.sh ubuntu@localhost:/tmp\" > \"$HOME/ubuntu-cloud-init/_scp_config_to_qemu_machine.sh\""
      ]
    },
    {
      "description"                : "Get _mount_qnap.sh so it can be copied to VM",
      "suppressOutput"             : false,
      "suppressDiagnostics": true,
      "showPreAndPostSpawnMessages": true,
      "outputColor"                : "",
      "useSudo"                    : false,
      "command"                    : "bash",
      "args"                       : [
        "-c",
        "wget -O $HOME/ubuntu-cloud-init/_mount_qnap.sh https://raw.githubusercontent.com/jreeme/firmament-bash/master/command-json/cloud-init-config/_mount_qnap.sh"
      ]
    },
    {
      "description"                : "Get _config.sh so it can be copied to VM",
      "suppressOutput"             : false,
      "suppressDiagnostics": true,
      "showPreAndPostSpawnMessages": true,
      "outputColor"                : "",
      "useSudo"                    : false,
      "command"                    : "bash",
      "args"                       : [
        "-c",
        "wget -O $HOME/ubuntu-cloud-init/_config.sh https://raw.githubusercontent.com/jreeme/firmament-bash/master/command-json/cloud-init-config/_config.sh"
      ]
    },
    {
      "description"                : "Create '_run_seed_img.sh' to build cdrom boot image",
      "suppressOutput"             : false,
      "suppressDiagnostics": true,
      "showPreAndPostSpawnMessages": true,
      "outputColor"                : "",
      "useSudo"                    : false,
      "command"                    : "bash",
      "suppressFinalError"         : true,
      "args"                       : [
        "-c",
        "[[ ! -f \"$HOME/ubuntu-cloud-init/_run_seed_img.sh\" ]] && echo \"#!/usr/bin/env bash\nkvm -m 8192 -smp 4 -cdrom seed.img -device e1000,netdev=user.0 -netdev user,id=user.0,hostfwd=tcp::5555-:22 -drive file=xenial-server-cloudimg-amd64-disk1.img,if=virtio,cache=writeback,index=0\" > \"$HOME/ubuntu-cloud-init/_run_seed_img.sh\""
      ]
    },
    {
      "description"                : "Create '_ssh.sh' to ssh into running kvm image",
      "suppressOutput"             : false,
      "suppressDiagnostics": true,
      "showPreAndPostSpawnMessages": true,
      "outputColor"                : "",
      "useSudo"                    : false,
      "command"                    : "bash",
      "suppressFinalError"         : true,
      "args"                       : [
        "-c",
        "[[ ! -f \"$HOME/ubuntu-cloud-init/_ssh.sh\" ]] && echo \"#!/usr/bin/env bash\nssh -p 5555 ubuntu@localhost\" > \"$HOME/ubuntu-cloud-init/_ssh.sh\""
      ]
    },
    {
      "description"                : "Download the QCOW2 Ubuntu16 Cloud Image (with cloud-init)",
      "suppressOutput"             : false,
      "suppressDiagnostics": true,
      "showPreAndPostSpawnMessages": true,
      "outputColor"                : "",
      "useSudo"                    : false,
      "command"                    : "bash",
      "suppressFinalError"         : true,
      "args"                       : [
        "-c",
        "[[ ! -f \"$HOME/ubuntu-cloud-init/xenial-server-cloudimg-amd64-disk1.img\" ]] && wget http://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img -O \"$HOME/ubuntu-cloud-init/xenial-server-cloudimg-amd64-disk1.img\""
      ]
    },
    {
      "description"                : "apt-get install [...]",
      "suppressOutput"             : false,
      "suppressDiagnostics": true,
      "showPreAndPostSpawnMessages": true,
      "useSudo"                    : true,
      "command"                    : "apt-get",
      "args"                       : [
        "install",
        "-y",
        "qemu-kvm"
      ]
    }
  ],
  "serialSynchronizedCommands": [
    {
      "description"                : "[sudo] chmod 755 _build_seed_img.sh",
      "suppressOutput"             : false,
      "suppressDiagnostics": true,
      "showPreAndPostSpawnMessages": true,
      "outputColor"                : "",
      "useSudo"                    : true,
      "command"                    : "bash",
      "args"                       : [
        "-c",
        "chmod 755 \"$HOME/ubuntu-cloud-init/_build_seed_img.sh\" \"$HOME/ubuntu-cloud-init/_run_seed_img.sh\" \"$HOME/ubuntu-cloud-init/_config.sh\" \"$HOME/ubuntu-cloud-init/_scp_config_to_qemu_machine.sh\" \"$HOME/ubuntu-cloud-init/_ssh.sh\" \"$HOME/ubuntu-cloud-init/_mount_qnap.sh\""
      ]
    }
  ]
}
