Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit f10cf52

Browse files
committed
refactor: remove redundant SSH verification methods replaced by Ansible
- Remove _verify_ssh_key_auth() method (replaced by Ansible ping module) - Remove _show_final_summary() method (replaced by Ansible system facts gathering) - Remove manual SSH reconnection and Docker/firewall checking logic - Simplify execute() method flow: cloud-init wait → Ansible verification → done - Update _run_ansible_verification() to include final completion message - Remove '(experimental)' label from Ansible verification - it's now the primary method - Reduces code complexity while maintaining all verification functionality through Ansible - All tests passing: unit, integration, linting
1 parent b3073ff commit f10cf52

File tree

1 file changed

+7
-109
lines changed

1 file changed

+7
-109
lines changed

lib/TorrustDeploy/App/Command/Provision.pm

Lines changed: 7 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,8 @@ sub execute {
6262
# Wait for cloud-init completion
6363
$self->_wait_for_cloud_init($ssh_connection);
6464

65-
# Force reconnection after cloud-init completes (VM reboots during cloud-init)
66-
say "🔄 Refreshing SSH connection after cloud-init reboot...";
67-
STDOUT->flush();
68-
$ssh_connection->force_reconnect();
69-
70-
# Verify SSH key authentication after cloud-init completes
71-
$self->_verify_ssh_key_auth($ssh_connection);
72-
73-
# Run Ansible post-provision verification (experimental)
65+
# Run Ansible post-provision verification
7466
$self->_run_ansible_verification($vm_ip, $work_dir);
75-
76-
# Show final summary
77-
$self->_show_final_summary($ssh_connection);
7867
}
7968

8069
sub _copy_templates {
@@ -250,58 +239,6 @@ sub _wait_for_cloud_init {
250239
}
251240
}
252241

253-
sub _show_final_summary {
254-
my ($self, $ssh_connection) = @_;
255-
256-
say "📦 Final system summary:";
257-
STDOUT->flush();
258-
259-
# Try multiple approaches to detect Docker
260-
my $docker_result;
261-
my $docker_method = "unknown";
262-
263-
# Method 1: Try with newgrp (preferred for group activation)
264-
$docker_result = $ssh_connection->execute_command('newgrp docker -c "docker --version" 2>&1');
265-
if ($docker_result->success) {
266-
$docker_method = "newgrp";
267-
} else {
268-
# Method 2: Try with sudo (fallback)
269-
$docker_result = $ssh_connection->execute_command('sudo docker --version 2>&1');
270-
if ($docker_result->success) {
271-
$docker_method = "sudo";
272-
} else {
273-
# Method 3: Try direct command (may fail due to group membership)
274-
$docker_result = $ssh_connection->execute_command('docker --version 2>&1');
275-
if ($docker_result->success) {
276-
$docker_method = "direct";
277-
}
278-
}
279-
}
280-
281-
my $docker_version;
282-
if ($docker_result->success) {
283-
$docker_version = $docker_result->output . " (via $docker_method)";
284-
} else {
285-
$docker_version = "Docker not available - all methods failed";
286-
}
287-
288-
chomp $docker_version if $docker_version;
289-
say " Docker: $docker_version";
290-
STDOUT->flush();
291-
292-
# Check firewall status
293-
294-
my $ufw_result = $ssh_connection->execute_command('sudo ufw status | head -1');
295-
my $ufw_status = $ufw_result->success ? $ufw_result->output : "UFW not available";
296-
chomp $ufw_status if $ufw_status;
297-
say " Firewall: $ufw_status" if $ufw_status;
298-
STDOUT->flush();
299-
300-
say "Provisioning completed successfully!";
301-
say "VM is ready at IP: " . $ssh_connection->host;
302-
STDOUT->flush();
303-
}
304-
305242
sub _print_cloud_init_logs {
306243
my ($self, $ssh_connection) = @_;
307244

@@ -325,55 +262,11 @@ sub _print_cloud_init_logs {
325262
}
326263
}
327264

328-
sub _verify_ssh_key_auth {
329-
my ($self, $ssh_connection) = @_;
330-
331-
say "🔑 Checking SSH key authentication...";
332-
STDOUT->flush();
333-
334-
# SSH authentication might need time to fully stabilize after cloud-init reboot
335-
# Try with progressive delays: immediate, 5s, 10s, 15s
336-
my @retry_delays = (0, 5, 10, 15);
337-
338-
for my $attempt (0..$#retry_delays) {
339-
if ($attempt > 0) {
340-
my $delay = $retry_delays[$attempt];
341-
say "⏳ Waiting ${delay}s before retry attempt " . ($attempt + 1) . "...";
342-
STDOUT->flush();
343-
sleep $delay;
344-
}
345-
346-
# Create a fresh SSH connection for key authentication test
347-
# This ensures we don't have any state issues from cloud-init monitoring
348-
my $fresh_ssh = TorrustDeploy::Infrastructure::SSH::Connection->new(
349-
host => $ssh_connection->host
350-
);
351-
352-
if ($fresh_ssh->test_key_connection()) {
353-
say "✅ SSH key authentication is working correctly!";
354-
say "You can now connect using: ssh -i " . $fresh_ssh->ssh_key_path . " " . $fresh_ssh->username . "@" . $fresh_ssh->host;
355-
STDOUT->flush();
356-
return;
357-
}
358-
359-
if ($attempt < $#retry_delays) {
360-
say "⚠️ SSH key authentication failed, will retry...";
361-
STDOUT->flush();
362-
}
363-
}
364-
365-
# All retries failed
366-
say "❌ SSH key authentication failed after all retries";
367-
STDOUT->flush();
368-
$self->_print_cloud_init_logs($ssh_connection);
369-
die "SSH key authentication failed";
370-
}
371-
372265
sub _run_ansible_verification {
373266
my ($self, $vm_ip, $work_dir) = @_;
374267

375268
say "";
376-
say "🎭 Starting Ansible post-provision verification (experimental)...";
269+
say "🎭 Starting Ansible post-provision verification...";
377270
STDOUT->flush();
378271

379272
# Set up Ansible working directory
@@ -386,7 +279,12 @@ sub _run_ansible_verification {
386279
# Run verification playbook
387280
$ansible->run_verification($ansible_dir);
388281

282+
# Final completion message
389283
say "";
284+
say "✅ Provisioning completed successfully!";
285+
say "VM is ready at IP: $vm_ip";
286+
say "You can connect using: ssh -i ~/.ssh/testing_rsa torrust@$vm_ip";
287+
STDOUT->flush();
390288
}
391289

392290
1;

0 commit comments

Comments
 (0)