knife-proxmox-ve 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bff2fdcc58a1aeadf186e297e838ddb91510536f7cf0169ccb25a3091c590931
4
- data.tar.gz: 9cdc6b30bfe1a9d8da2feb3f8cf622973dbb0ab553c13c10a3a9729ea444a46a
3
+ metadata.gz: fbd3b9c6dcb50cfa79244a9ff639c08e2b4417bdc99416a870b0a9886367a888
4
+ data.tar.gz: e4c7f6ab01e458c4794651ac8927f8aecb5a1e42368b7222862f25e6b85d08bc
5
5
  SHA512:
6
- metadata.gz: 118d4dd196b869f226c11801b728b4d71661c9aa9756210b3857bf6f629c45515199a9b2e0b9b0f27b07bbf1cee995de81eaa1e1e8102a228d415eae7a94a460
7
- data.tar.gz: b2b0d7b679086f772f7d844c22635c9a749110405362788ece0e7de99a23eec68a97c1e7e18ddfdad30500a5bfb606e8f8ed4b396a61faa9a32a0a1a4f2226ae
6
+ metadata.gz: 7633f2ed9ae45c09629598331707b209076eb32e477239a5cc91732339eb8947f4637631ef974e99604eac66fbb8ef59ed5ebab07ec24dee427d1037053ef5c6
7
+ data.tar.gz: 3df97180d137de70f035416f88d487b13d3f562ec02087b2b8e382abea081dcc7b91c0fa6475ef15453dde08d857290e8b703f39d2015aca121228bba7f60e73
data/README.md CHANGED
@@ -45,12 +45,16 @@ knife[:proxmox_clusters] = {
45
45
  verify_ssl: true, # optional (default true); false warns every run
46
46
 
47
47
  # Optional per-cluster provisioning defaults (any CLI flag overrides these):
48
- storage: "local-lvm",
49
- bridge: "vmbr0",
50
- ciuser: "ubuntu",
51
- nameserver: "10.0.0.1",
52
- searchdomain: "example.com",
53
- target_node: nil,
48
+ storage: "local-lvm",
49
+ bridge: "vmbr0",
50
+ ciuser: "ubuntu",
51
+ ssh_public_key: "~/.ssh/id_ed25519.pub", # default authorized key; satisfies the auth
52
+ # requirement without --ssh-public-key. For
53
+ # `vm bootstrap`, :ciuser also becomes the
54
+ # default --connection-user.
55
+ nameserver: "10.0.0.1",
56
+ searchdomain: "example.com",
57
+ target_node: nil,
54
58
  },
55
59
  }
56
60
 
@@ -150,13 +154,14 @@ Both commands share the provisioning flags below.
150
154
  | `--bridge vmbrN` / `--vlan TAG` | net0 bridge and VLAN tag (needs a VLAN-aware bridge). |
151
155
  | `--ip CIDR\|dhcp` / `--gateway IP` / `--prefix N` | Static IPv4 (`10.0.10.5/24`, or a bare IP with `--prefix`) or `dhcp`. |
152
156
  | `--nameserver IP` / `--searchdomain DOMAIN` | cloud-init DNS. |
153
- | `--ciuser USER` | cloud-init user. |
154
- | `--ssh-public-key PATH` | Public key injected via cloud-init (preferred auth). |
157
+ | `--ciuser USER` | cloud-init user. For `vm bootstrap`, also the default `--connection-user`. |
158
+ | `--ssh-public-key PATH` | Public key injected via cloud-init (preferred auth). Falls back to the cluster's `:ssh_public_key`. |
155
159
  | `--cipassword` | Prompt (no echo) for a cloud-init password; or set `KNIFE_PROXMOX_CIPASSWORD`. |
156
160
  | `--clone-timeout SEC` / `--boot-timeout SEC` | Clone and boot/SSH wait limits (default 600 / 300). |
157
161
 
158
162
  For `vm bootstrap`, the standard `knife bootstrap` options are inherited: `-N/--node-name`,
159
- `-r/--run-list`, `-E/--environment`, `--connection-user`, `--ssh-identity-file`,
163
+ `-r/--run-list`, `-E/--environment`, `--connection-user` (defaults to the resolved `:ciuser`,
164
+ since cloud-init creates the guest account under that name), `--ssh-identity-file`,
160
165
  `--bootstrap-version`, `--ssh-verify-host-key` (defaults to `:accept_new` for the
161
166
  freshly-created host), `--yes`, etc. They do not apply to `vm create`, which never bootstraps.
162
167
 
@@ -110,7 +110,8 @@ class Chef
110
110
 
111
111
  option :ssh_public_key,
112
112
  long: "--ssh-public-key PATH",
113
- description: "Path to an SSH PUBLIC key authorized for the cloud-init user."
113
+ description: "Path to an SSH PUBLIC key authorized for the cloud-init user. " \
114
+ "Defaults to the cluster's :ssh_public_key when set."
114
115
 
115
116
  option :cipassword,
116
117
  long: "--cipassword",
@@ -246,8 +247,8 @@ class Chef
246
247
  return if @ssh_public_key || @cipassword
247
248
 
248
249
  ui.fatal!(
249
- "no SSH credential for the new VM: pass --ssh-public-key PATH, or provide a " \
250
- "cloud-init password via #{ENV_CIPASSWORD} or --cipassword"
250
+ "no SSH credential for the new VM: pass --ssh-public-key PATH (or set the cluster's " \
251
+ ":ssh_public_key), or provide a cloud-init password via #{ENV_CIPASSWORD} or --cipassword"
251
252
  )
252
253
  end
253
254
 
@@ -264,7 +265,7 @@ class Chef
264
265
  # looks like a private key (a common copy-paste mistake that must never be
265
266
  # uploaded as an authorized key).
266
267
  def resolve_ssh_public_key
267
- path = config[:ssh_public_key]
268
+ path = from_cli_or_cluster(:ssh_public_key)
268
269
  return nil if blank?(path)
269
270
 
270
271
  @ssh_public_key_path = File.expand_path(path)
@@ -28,13 +28,30 @@ class Chef
28
28
  CINC_PRODUCT = "cinc"
29
29
  CINC_INSTALL_URL = "https://omnitruck.cinc.sh/install.sh"
30
30
 
31
- # A freshly cloned VM often still runs cloud-init (which itself drives apt) when SSH first
32
- # answers. Installing the client then races cloud-init for the dpkg lock and fails
33
- # non-deterministically. Block on cloud-init completion before the omnibus install so a
34
- # single `vm bootstrap` is reliable. Guarded so non-cloud-init images don't error, and
35
- # `|| true` so a degraded/errored cloud-init state still lets the bootstrap proceed.
36
- CLOUD_INIT_WAIT_COMMAND =
37
- "if command -v cloud-init >/dev/null 2>&1; then cloud-init status --wait >/dev/null 2>&1 || true; fi"
31
+ # A freshly cloned VM is still settling when SSH first answers, and two independent
32
+ # subsystems contend for the dpkg lock: cloud-init (which itself drives apt) and the
33
+ # apt-daily / unattended-upgrades systemd timers, which fire on their own schedule even
34
+ # after cloud-init reports done. Installing the client or the first client run's package
35
+ # resources then races them for the lock and fails non-deterministically. Clear the field
36
+ # before the omnibus install, in order:
37
+ # 1. wait for cloud-init to finish;
38
+ # 2. stop the apt-daily / unattended-upgrades timers and any in-flight run, so nothing
39
+ # grabs the lock again for the rest of this boot (`stop`, not `disable`/`mask`: the
40
+ # services return on the next reboot, leaving the image unchanged);
41
+ # 3. block (bounded) until the dpkg lock a stopped run may still hold is released.
42
+ # Every step is guarded on the tool existing and `|| true`, so non-cloud-init / non-systemd
43
+ # / non-apt images and degraded states still let the bootstrap proceed.
44
+ PREINSTALL_WAIT_COMMAND = <<~SH
45
+ if command -v cloud-init >/dev/null 2>&1; then cloud-init status --wait >/dev/null 2>&1 || true; fi
46
+ if command -v systemctl >/dev/null 2>&1; then
47
+ systemctl stop apt-daily.timer apt-daily-upgrade.timer apt-daily.service apt-daily-upgrade.service unattended-upgrades.service >/dev/null 2>&1 || true
48
+ fi
49
+ if command -v flock >/dev/null 2>&1; then
50
+ for lock in /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock; do
51
+ [ -e "$lock" ] && flock -w 300 "$lock" true >/dev/null 2>&1 || true
52
+ done
53
+ fi
54
+ SH
38
55
 
39
56
  deps do
40
57
  require "chef/knife/bootstrap"
@@ -60,8 +77,8 @@ class Chef
60
77
  # TOFU: a freshly cloned VM has no entry in known_hosts. Accept its key on
61
78
  # first connect rather than failing the bootstrap or disabling verification.
62
79
  config[:ssh_verify_host_key] ||= :accept_new
63
- # Wait for cloud-init to finish before the bootstrap installs the client (see constant).
64
- config[:bootstrap_preinstall_command] ||= CLOUD_INIT_WAIT_COMMAND
80
+ # Drain cloud-init and the dpkg lock before the bootstrap installs the client (see constant).
81
+ config[:bootstrap_preinstall_command] ||= PREINSTALL_WAIT_COMMAND
65
82
  end
66
83
 
67
84
  # The bootstrap target host does not exist yet — it is resolved to the VM's IP
@@ -95,6 +112,11 @@ class Chef
95
112
  def apply_provision_auth!(spec)
96
113
  super
97
114
 
115
+ # cloud-init creates the guest account as :ciuser, so the bootstrap must connect as that
116
+ # same user. Fall back to it when the operator did not pass an explicit --connection-user.
117
+ ciuser = from_cli_or_cluster(:ciuser)
118
+ config[:connection_user] ||= ciuser if ciuser
119
+
98
120
  config[:connection_password] = @cipassword if @cipassword
99
121
 
100
122
  return unless @ssh_public_key
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Knife
4
4
  module Proxmox
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-proxmox-ve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Wojcieszonek