cloudinit
About
My cloud provider supports it. It's never been so easy to and fast to get a server up'n'running. The glue i was missing a long time.
Written in python3.
Install cloud-init with
1 apt install cloud-init
This will create lots of directories
find $(dpkg -L cloud-init) -maxdepth 0 -type d
/etc/cloud
/lib/systemd/system/cloud-* and the corresponding links in /etc/systemd
/usr/lib/cloud-init
/usr/lib/python3/dist-packages/cloudinit
/var/lib/cloud
Configure
user-data.txt
Don't forget to add the keyword #cloud-config in front of your cloud-init code.
Otherwise it will fail with:
… Unhandled non-multipart (text/x-not-multipart) userdata: …
Example user-data.txt
1 #cloud-config
2
3 timezone: Europe/Berlin
4
5 package_update: True
6 packages:
7 - apt-file
8 - aptitude
9 - bash-completion
10 - byobu
11 - btrfs-progs
12 - ca-certificates
13 - curl
14 - dmidecode
15 - dosfstools
16 - git
17 - htop
18 - iftop
19 - info
20 - iotop
21 - jq
22 - libcrack2
23 - locales
24 - lsb-release
25 - lsof
26 - man-db
27 - mc
28 - mlocate
29 - openssl
30 - parted
31 - pigz
32 - psmisc
33 - pv
34 - pwgen
35 - python3-apt
36 - rsync
37 - screen
38 - sqlite3
39 - strace
40 - sudo
41 - sysstat
42 - tmux
43 - unattended-upgrades
44 - vim
45 - wget
46 - zsh
47
48 users:
49 - name: root
50 ssh_authorized_keys:
51 - ssh-rsa your_pubkey_goes_here user@host
52 - name: tobias
53 gecos: "Tobias Stein,,,"
54 groups: sudo
55 ssh_authorized_keys:
56 - ssh-rsa your_pubkey_goes_here user@host
57
58 runcmd:
59 - [ git, clone, "git://git.grml.org/grml-etc-core.git", "/opt/grml-etc-core" ]
60
61 resolv_conf:
62 nameservers:
63 - 176.9.99.233
64 - 195.201.246.253
65 searchdomains:
66 - rockstable.it.
67 - rockstable.org.
68 options:
69 timeout: 5
70
71 write_files:
72 - path: "/etc/vim/vimrc.local"
73 owner: "root:root"
74 content: |
75 " All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
76 " the call to :runtime you can find below. If you wish to change any of those
77 " settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
78 " will be overwritten everytime an upgrade of the vim packages is performed.
79 " It is recommended to make changes after sourcing debian.vim since it alters
80 " the value of the 'compatible' option.
81
82 " This line should not be removed as it ensures that various options are
83 " properly set to work with the Vim-related packages available in Debian.
84 runtime! debian.vim
85
86 " Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
87 " This happens after /etc/vim/vimrc(.local) are loaded, so it will override
88 " any settings in these files.
89 " If you don't want that to happen, uncomment the below line to prevent
90 " defaults.vim from being loaded.
91 let g:skip_defaults_vim = 1
92
93 " Uncomment the next line to make Vim more Vi-compatible
94 " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
95 " options, so any other options should be set AFTER setting 'compatible'.
96 "set compatible
97
98 " Vim5 and later versions support syntax highlighting. Uncommenting the next
99 " line enables syntax highlighting by default.
100 syntax on
101
102 " If using a dark background within the editing area and syntax highlighting
103 " turn on this option as well
104 set background=dark
105
106 " Uncomment the following to have Vim jump to the last position when
107 " reopening a file
108 au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
109
110 " Uncomment the following to have Vim load indentation rules and plugins
111 " according to the detected filetype.
112 filetype plugin indent on
113
114 " The following are commented out as they cause vim to behave a lot
115 " differently from regular Vi. They are highly recommended though.
116 set showcmd " Show (partial) command in status line.
117 set showmatch " Show matching brackets.
118 "set ignorecase " Do case insensitive matching
119 "set smartcase " Do smart case matching
120 "set incsearch " Incremental search
121 "set autowrite " Automatically save before commands like :next and :make
122 "set hidden " Hide buffers when they are abandoned
123 "set mouse=a " Enable mouse usage (all modes)
124 - path: "/root/.bashrc"
125 owner: "root:root"
126 content: |
127 # ~/.bashrc: executed by bash(1) for non-login shells.
128 #
129 # Note: PS1 and umask are already set in /etc/profile. You should not
130 # need this unless you want different defaults for root.
131 # PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
132 umask 022
133
134 # You may uncomment the following lines if you want `ls' to be colorized:
135 export LS_OPTIONS='--color=auto'
136 eval "`dircolors`"
137 alias ls='ls $LS_OPTIONS'
138 alias ll='ls $LS_OPTIONS -l'
139 alias l='ls $LS_OPTIONS -lA'
140
141 alias ..='cd ..'
142 alias ...='cd ../..'
143
144 # Some more alias to avoid making mistakes:
145 # alias rm='rm -i'
146 # alias cp='cp -i'
147 # alias mv='mv -i'
148
149 package_upgrade: True
150 package_reboot_if_required: True
151
152 # vim: et:ts=2:sw=2:
Providing the file
The systemd-generators enable the service
/usr/lib/systemd/system-generators/cloud-init-generator
The following script detects the data source
/usr/lib/cloud-init/ds-identify
As a local file:
/var/lib/cloud/seed/user-data
Log
There shoould be a log at
/var/log/cloud-init.log