Cloud-init: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(12 intermediate revisions by the same user not shown)
Line 9: Line 9:


* [[Linux_Hostname#cloud-init_and_hostname|Linux Hostname]]
* [[Linux_Hostname#cloud-init_and_hostname|Linux Hostname]]
=Read before going further=
<font color=red>TODO</font>:


=Overview=
=Overview=
Line 25: Line 21:


The cloud-init runtime is written in python.
The cloud-init runtime is written in python.
=Installation=
<syntaxhighlight lang='bash'>
yum install cloud-init
</syntaxhighlight>


=Configuration=
=Configuration=


<pre>
cloud-init configuration is maintained in a YAML-format file:
 
<syntaxhighlight lang='text'>
/etc/cloud/cloud.cfg
/etc/cloud/cloud.cfg
</pre>
</syntaxhighlight>
 
Additional files from /etc/cloud/cloud.cfg.d are read in lexical order.


=Example=
==Example==


<pre>
<syntaxhighlight lang='yaml'>
users:
users:
  - default
  - default
Line 97: Line 101:


# vim:syntax=yaml
# vim:syntax=yaml
</pre>
</syntaxhighlight>
 
=Concepts=
==Cloud Dir==
The "cloud_dir" is configured in [[#Configuration|/etc/cloud/cloud.cfg]]. It is <code>/var/lib/cloud</code> by default.
 
<syntaxhighlight lang='text'>
.
├── data
│   ├── instance-id
│   ├── previous-datasource
│   ├── previous-hostname
│   ├── previous-instance-id
│   ├── result.json
│   ├── set-hostname
│   └── status.json
├── handlers
├── instance -> /var/lib/cloud/instances/i-03e84d220850fa423
├── instances
│   ├── i-021c7fbfb1924dac1
│   │   └── ...
│   └── i-03e84d220850fa423
│      ├── boot-finished
│      ├── cloud-config.txt
│      ├── datasource
│      ├── handlers
│      ├── obj.pkl
│      ├── scripts
│      ├── sem
│      │   ├── config_amazonlinux_repo_https
│      │   ├── config_disk_setup
│      │   ├── config_keys_to_console
│      │   ├── config_locale
│      │   ├── config_mounts
│      │   ├── config_package_update_upgrade_install
│      │   ├── config_phone_home
│      │   ├── config_power_state_change
│      │   ├── config_resolv_conf
│      │   ├── config_rsyslog
│      │   ├── config_runcmd
│      │   ├── config_scripts_per_instance
│      │   ├── config_scripts_user
│      │   ├── config_set_hostname
│      │   ├── config_set_passwords
│      │   ├── config_ssh
│      │   ├── config_ssh_authkey_fingerprints
│      │   ├── config_timezone
│      │   ├── config_users_groups
│      │   ├── config_write_files
│      │   ├── config_write_metadata
│      │   ├── config_yum_add_repo
│      │   ├── config_yum_configure
│      │   └── consume_data
│      ├── user-data.txt
│      ├── user-data.txt.i
│      ├── vendor-data.txt
│      └── vendor-data.txt.i
├── scripts
│   ├── per-boot
│   │    └── 050-someprogram-start.sh
│   ├── per-instance
│   ├── per-once
│   └── vendor
├── seed
└── sem
    └── config_scripts_per_once.once
</syntaxhighlight>
 
===<tt>scripts/per-boot</tt>===
 
This is where logic that must be executed on each boot goes. The <code><digit><digit>-*</code> naming conventions ensures that scripts with lower numeric prefix are executed first.


=Setting hostname=
=Setting hostname=
Line 116: Line 190:
  ...
  ...
</pre>
</pre>
=Organizatorium=

Latest revision as of 19:24, 1 July 2021

External

Internal

Overview

Cloud-init is an industry standard method for cross-platform cloud instance initialization. It is supported across all major cloud providers.

Cloud instances are initialized from a disk image and instance data. Instance data consists of:

  • Cloud metadata
  • User data
  • Vendor data

Cloud-init identifies during boot the cloud the instance is running, reads any provided cloud metadata from the cloud and initializes the system accordingly - sets up network, storage, SSH access, etc. Cloud-init then parses and processes user data, if available and vendor data, if available.

The cloud-init runtime is written in python.

Installation

yum install cloud-init

Configuration

cloud-init configuration is maintained in a YAML-format file:

/etc/cloud/cloud.cfg

Additional files from /etc/cloud/cloud.cfg.d are read in lexical order.

Example

users:
 - default

disable_root: 1
ssh_pwauth:   0

mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
resize_rootfs_tmp: /dev
ssh_deletekeys:   0
ssh_genkeytypes:  ~
syslog_fix_perms: ~

cloud_init_modules:
 - migrator
 - bootcmd
 - write-files
 - growpart
 - resizefs
 - rsyslog
 - users-groups
 - ssh

cloud_config_modules:
 - mounts
 - locale
 - set-passwords
 - yum-add-repo
 - package-update-upgrade-install
 - timezone
 - puppet
 - chef
 - salt-minion
 - mcollective
 - disable-ec2-metadata
 - runcmd

cloud_final_modules:
 - rightscale_userdata
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - ssh-authkey-fingerprints
 - keys-to-console
 - phone-home
 - final-message

system_info:
  default_user:
    name: ec2-user
    lock_passwd: true
    gecos: Cloud User
    groups: [wheel, adm, systemd-journal]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
  distro: rhel
  paths:
    cloud_dir: /var/lib/cloud
    templates_dir: /etc/cloud/templates
  ssh_svcname: sshd

# vim:syntax=yaml

Concepts

Cloud Dir

The "cloud_dir" is configured in /etc/cloud/cloud.cfg. It is /var/lib/cloud by default.

.
├── data
│   ├── instance-id
│   ├── previous-datasource
│   ├── previous-hostname
│   ├── previous-instance-id
│   ├── result.json
│   ├── set-hostname
│   └── status.json
├── handlers
├── instance -> /var/lib/cloud/instances/i-03e84d220850fa423
├── instances
│   ├── i-021c7fbfb1924dac1
│   │   └── ...
│   └── i-03e84d220850fa423
│       ├── boot-finished
│       ├── cloud-config.txt
│       ├── datasource
│       ├── handlers
│       ├── obj.pkl
│       ├── scripts
│       ├── sem
│       │   ├── config_amazonlinux_repo_https
│       │   ├── config_disk_setup
│       │   ├── config_keys_to_console
│       │   ├── config_locale
│       │   ├── config_mounts
│       │   ├── config_package_update_upgrade_install
│       │   ├── config_phone_home
│       │   ├── config_power_state_change
│       │   ├── config_resolv_conf
│       │   ├── config_rsyslog
│       │   ├── config_runcmd
│       │   ├── config_scripts_per_instance
│       │   ├── config_scripts_user
│       │   ├── config_set_hostname
│       │   ├── config_set_passwords
│       │   ├── config_ssh
│       │   ├── config_ssh_authkey_fingerprints
│       │   ├── config_timezone
│       │   ├── config_users_groups
│       │   ├── config_write_files
│       │   ├── config_write_metadata
│       │   ├── config_yum_add_repo
│       │   ├── config_yum_configure
│       │   └── consume_data
│       ├── user-data.txt
│       ├── user-data.txt.i
│       ├── vendor-data.txt
│       └── vendor-data.txt.i
├── scripts
│   ├── per-boot
│   │    └── 050-someprogram-start.sh
│   ├── per-instance
│   ├── per-once
│   └── vendor
├── seed
└── sem
    └── config_scripts_per_once.once

scripts/per-boot

This is where logic that must be executed on each boot goes. The <digit><digit>-* naming conventions ensures that scripts with lower numeric prefix are executed first.

Setting hostname

Done by the following modules, that work with systemd-hostnamed:

...

cloud_init_modules:
  
 ...

 - set_hostname
 - update_hostname
 - update_etc_hosts

 ...