Jan Walraven
DevOps



Categories:
  • Arduino (2)
  • CSS (3)
  • Docker (11)
  • ESXi (1)
  • Git (4)
  • Google Cloud (3)
  • Javascript (6)
  • Kubernetes (4)
  • Linux (36)
  • Mac (7)
  • Magento (4)
  • Mysql (14)
  • PHP (9)
  • Zend framework 2 (9)
  • Posted on March 6, 2017

    If you are running CoreOS in a virtual environment, you can automatically configure CoreOS by cloud-config. This can be achieved by creating a configdrive ISO and mount it at boottime. CoreOS will scan the CD-ROM and will execute the cloud-config.

    Script to generate the ISO based on the cloud-config

    This script will generate an configdrive ISO based on the given cloud-config.

    Supports the following OS

    1. Mac OS
    2. Linux

    Usage

    $ createIso.sh --cloud-config cloud-config.yml --name application

    createiso.sh

    #!/usr/bin/env bash
    
    PATH_TEMP=/tmp/new-drive
    PATH_ISO_MAC=`which hdiutil`
    PATH_ISO_LINUX=`which mkisofs`
    
    ISO_COMMAND="none"
    
    if [[  -f "${PATH_ISO_MAC}" ]]; then
        echo "MacOS Detected, using hdiutil tool"
        ISO_COMMAND="mac"
    fi
    
    if [[  -f "${PATH_ISO_LINUX}" ]]; then
        echo "Linux Detected, using mkisofs tool"
        ISO_COMMAND="linux"
    fi
    
    if [[ "${ISO_COMMAND}" == "none" ]]; then
        echo "Cannot find hdiutil for mac or mkisofs for linux."
        echo "Please install required tools"
        exit;
    fi
    
    while [[ $# > 1 ]]
    do
        key="$1"
        case $key in
            --name)
            NAME="$2"
            shift # past argument
            ;;
            --cloud-config)
            CLOUD_CONFIG="$2"
            shift # past argument
            ;;
            *)
                # unknown option
            ;;
        esac
        shift # past argument or value
    done
    
    if [ -z "${CLOUD_CONFIG}" ]; then
        echo "usage: createIso.sh --cloud-config cloud-config.yml --name application";
        exit
    fi
    if [ -z "${NAME}" ]; then
        echo "usage: createIso.sh --cloud-config cloud-config.yml --name application";
        exit;
    fi
    
    if [[ ! -f "${CLOUD_CONFIG}" ]]; then
        echo "Cloud config file not found (${CLOUD_CONFIG})"
        exit;
    fi
    
    echo "Creating config drive with cloud-config '${CLOUD_CONFIG}'"
    mkdir -p ${PATH_TEMP}/openstack/latest
    cp ${CLOUD_CONFIG} ${PATH_TEMP}/openstack/latest/user_data
    
    if [[ "${ISO_COMMAND}" == "linux" ]]; then
        mkisofs -R -V config-2 -o configdrive-${NAME}.iso ${PATH_TEMP}
    fi
    
    if [[ "${ISO_COMMAND}" == "mac" ]]; then
        hdiutil makehybrid -iso -joliet -default-volume-name config-2 -o configdrive-${NAME}.iso ${PATH_TEMP}
    fi
    
    #Cleanup
    rm -r ${PATH_TEMP}