Cloud-init: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 160: Line 160:
├── scripts
├── scripts
│   ├── per-boot
│   ├── per-boot
│   │   └── 050-someprogram-start.sh
│   │   └── 050-someprogram-start.sh
│   ├── per-instance
│   ├── per-instance
│   ├── per-once
│   ├── per-once

Revision as of 18:44, 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

Setting hostname

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

...

cloud_init_modules:
  
 ...

 - set_hostname
 - update_hostname
 - update_etc_hosts

 ...