Code Monkey home page Code Monkey logo

cloudinittool's Introduction

cloudinittool

cloudinittool is a small command line tool for managing cloud-init local datasource.

It it not a general tool, but a minimal tool just for my needs to boot a Ubuntu VM on multipass and Hyper-V.

Usage

Usage: cloudinittool <subcommand> [options]

subcommands:
  modify-user-data    Modify user-data.
  make-iso            Make an ISO image

Run cloudinittool <subcommand> -h to show help for subcommand.
Usage: cloudinittool modify-user-data [options]

options:
  -in string
        input user-data yaml file. required.
  -out string
        output user-data yaml file. required.
  -passwd
        show prompt to input default user password. optional.
  -pub-key string
        add ssh public key to ssh_authorized_keys. optional.
Usage: cloudinittool make-iso [options]

options:
  -meta-data string
        input meta-data yaml file. optional.
  -network-config string
        input network-config yaml file. optional.
  -out string
        output ISO image file. required.
  -user-data string
        input user-data yaml file. required.

Example

Add password and ssh_authorized_keys to user-data file

The input file for modify-user-data subcommand is like below:

user-data.in.yml

#cloud-config
locale: en_US.UTF8
timezone: Asia/Tokyo
package_upgrade: true
package_reboot_if_required: true
apt:
  primary:
    arches:
    - amd64
    - default
    uri: http://jp.archive.ubuntu.com/ubuntu/
chpasswd:
  expire: false

Generate ssh key pair, for example:

ssh-keygen -t ed25519 -f ~/.ssh/vm.id_ed25519 -C vm -N ''

Run the following command to add the password and an authorized key for the default user. You can input the password at Password: prompt and the Confirm password: prompt.

cloudinittool modify-user-data -in user-data.in.yml -out user-data \
  -passwd -pub-key ~/.ssh/vm.id_ed25519.pub

The output file user-data is like below:

#cloud-config
locale: en_US.UTF8
timezone: Asia/Tokyo
package_upgrade: true
package_reboot_if_required: true
apt:
  primary:
    arches:
    - amd64
    - default
    uri: http://jp.archive.ubuntu.com/ubuntu/
password: $6$...SALT...$...HASHED_PASSWORD_HERE...
chpasswd:
  expire: false
ssh_authorized_keys:
- |
  ssh-ed25519 ...YOUR_PUBLIC_KEY_HERE...

Use user-data file when launching a VM with multipass

You can use pass this user-data file to multipass launch with the --cloud-init option.

multipass launch --name primary --cpus 2 --mem 4G --disk 100G --cloud-init user-data

Make a data source ISO image for Hyper-V

An example network-config in Networking Config Version 2 format:

version: 2
ethernets:
    eth0:
        dhcp4: false
        addresses:
            - 192.168.254.2/24
        gateway4: 192.168.254.1
        nameservers:
            addresses: [8.8.8.8, 8.8.4.4]

You can make an ISO image to pass to launch a VM on Hyper-V, for example:

cloudinittool make-iso -user-data user-data -network-config network-config -out cloud-init.iso

cloudinittool's People

Contributors

hnakamur avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.