Class: Chef::Knife::ProxmoxVmBootstrap
- Inherits:
-
Bootstrap
- Object
- Bootstrap
- Chef::Knife::ProxmoxVmBootstrap
- Includes:
- ProxmoxBase, ProxmoxVmProvision
- Defined in:
- lib/chef/knife/proxmox_vm_bootstrap.rb
Overview
‘knife proxmox vm bootstrap NAME` — clone a Proxmox VE template, configure it, start it, wait for the guest to come up, then bootstrap it with Chef/CINC.
Subclasses Bootstrap (NOT Knife) so the whole post-provision lifecycle —connect, register, render, upload, perform — is inherited. We only fill the plugin hooks: setup, validate, create-instance, finalize. The clone→configure→start→wait pipeline and the CLI surface come from ProxmoxVmProvision (shared with ‘vm create`); this class adds the Chef bootstrap on top. The bootstrap target host is unknown until the VM exists, so #validate_name_args! is a deliberate no-op and the resolved IP is injected into @name_args in #plugin_create_instance!.
Constant Summary collapse
- CINC_PRODUCT =
Bootstrap defaults to the community CINC build: a plain (even Chef-branded) knife then installs cinc-client and never hits Chef’s commercial license gate. Opt into Chef with knife = “chef” (or “chef-ice”) in config.rb.
"cinc"- CINC_INSTALL_URL =
"https://omnitruck.cinc.sh/install.sh"- CLOUD_INIT_WAIT_COMMAND =
A freshly cloned VM often still runs cloud-init (which itself drives apt) when SSH first answers. Installing the client then races cloud-init for the dpkg lock and fails non-deterministically. Block on cloud-init completion before the omnibus install so a single ‘vm bootstrap` is reliable. Guarded so non-cloud-init images don’t error, and ‘|| true` so a degraded/errored cloud-init state still lets the bootstrap proceed.
"if command -v cloud-init >/dev/null 2>&1; then cloud-init status --wait >/dev/null 2>&1 || true; fi"
Constants included from ProxmoxVmProvision
Chef::Knife::ProxmoxVmProvision::ENV_CIPASSWORD, Chef::Knife::ProxmoxVmProvision::PRIVATE_KEY_MARKER, Chef::Knife::ProxmoxVmProvision::PUBLIC_KEY_PREFIXES, Chef::Knife::ProxmoxVmProvision::VMBR_PATTERN
Constants included from ProxmoxBase
Chef::Knife::ProxmoxBase::BYTE_UNITS, Chef::Knife::ProxmoxBase::ENV_SECRET_GLOBAL, Chef::Knife::ProxmoxBase::ENV_SECRET_PREFIX
Instance Method Summary collapse
- #plugin_create_instance! ⇒ Object
- #plugin_finalize ⇒ Object
-
#plugin_setup! ⇒ Object
plugin_setup! is the first hook Bootstrap#run invokes, so the CINC default is applied here — before render_template/perform_bootstrap build the omnibus install command.
- #plugin_validate_options! ⇒ Object
-
#validate_name_args! ⇒ Object
The bootstrap target host does not exist yet — it is resolved to the VM’s IP in #plugin_create_instance!.
Methods included from ProxmoxVmProvision
Methods included from ProxmoxBase
#human_bytes, #human_duration, included, #msg_pair, #proxmox_api, #proxmox_client, #proxmox_cluster_config, #proxmox_token_secret_present?
Instance Method Details
#plugin_create_instance! ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/chef/knife/proxmox_vm_bootstrap.rb', line 75 def plugin_create_instance! result = provision_vm! config[:chef_node_name] ||= @vm_name @name_args = [result.ip] @proxmox_result = result end |
#plugin_finalize ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/chef/knife/proxmox_vm_bootstrap.rb', line 83 def plugin_finalize result = @proxmox_result return unless result msg_provision_result(result) msg_pair("Chef node", config[:chef_node_name]) end |
#plugin_setup! ⇒ Object
plugin_setup! is the first hook Bootstrap#run invokes, so the CINC default is applied here — before render_template/perform_bootstrap build the omnibus install command. (In older knife this was done from a fetch_license override; knife 19.2 dropped that hook from the run sequence, so plugin_setup! is now the correct, earliest place.)
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/chef/knife/proxmox_vm_bootstrap.rb', line 56 def plugin_setup! default_bootstrap_to_cinc! config[:connection_protocol] ||= "ssh" config[:connection_port] ||= 22 # TOFU: a freshly cloned VM has no entry in known_hosts. Accept its key on # first connect rather than failing the bootstrap or disabling verification. config[:ssh_verify_host_key] ||= :accept_new # Wait for cloud-init to finish before the bootstrap installs the client (see constant). config[:bootstrap_preinstall_command] ||= CLOUD_INIT_WAIT_COMMAND end |
#plugin_validate_options! ⇒ Object
71 72 73 |
# File 'lib/chef/knife/proxmox_vm_bootstrap.rb', line 71 def (require_ssh_auth: true) end |
#validate_name_args! ⇒ Object
The bootstrap target host does not exist yet — it is resolved to the VM’s IP in #plugin_create_instance!. Override the inherited “must pass an FQDN” guard.
69 |
# File 'lib/chef/knife/proxmox_vm_bootstrap.rb', line 69 def validate_name_args!; end |