Sobes.tech
Middle+

How would you install software on a large number of machines if you do not have access to Ansible and Python?

sobes.tech AI

Answer from AI

Would you use a combination of command line scripts (Bash for Linux/Unix, Batch/PowerShell for Windows) and SSH/WinRM.

#!/bin/bash
# Example script for installing software on Linux via SSH

SOFTWARE_NAME="nginx"
REMOTE_HOSTS=("user@host1" "user@host2" "user@host3") # List of remote hosts

for host in "${REMOTE_HOSTS[@]}"; do
  echo "Installing $SOFTWARE_NAME on $host..."
  ssh "$host" "sudo apt-get update && sudo apt-get install -y $SOFTWARE_NAME"
  if [ $? -eq 0 ]; then
    echo "$SOFTWARE_NAME successfully installed on $host"
  else
    echo "Error installing $SOFTWARE_NAME on $host"
  fi
done

For Windows:

# Example script for installing software on Windows via WinRM

$softwareName = "notepadplusplus" # Example package name from Chocolatey
$remoteHosts = @("host1", "host2", "host3") # List of remote hosts

foreach ($host in $remoteHosts) {
  Write-Host "Installing $softwareName on $host..."
  # Example using Chocolatey (requires pre-installation on target machines)
  Invoke-Command -ComputerName $host -ScriptBlock { choco install $using:softwareName -y }
  if ($?) {
    Write-Host "$softwareName successfully installed on $host"
  } else {
    Write-Host "Error installing $softwareName on $host"
  }
}

It is also possible to use:

  1. SSH Key-based authentication: For automating login without password prompts.
  2. Centralized file distribution: Transferring installers or installation scripts to machines before execution.
  3. Cron/Task Scheduler: Using schedulers to perform installations at specific times or on a schedule.
  4. PXE Boot (Preboot Execution Environment): For deploying operating systems and basic software on "bare-metal" machines.
  5. Custom Bash/Batch/PowerShell scripts: Creating more complex scripts for configuration after installation.

Comparison table of approaches:

Method Advantages Disadvantages Applicability
Bash/SSH Widely available, simple for basic scenarios. Limited state management capabilities, error handling complexity. Linux/Unix systems.
Batch/PowerShell/WinRM Built-in Windows tools. Less standardized compared to SSH/Bash, requires WinRM setup. Windows systems.
Centralized files Convenient for distributing large files. Requires additional execution mechanisms on target machines. Any systems.
Cron/Task Scheduler Time-based automation. Not suitable for interactive installation or manual runs. Any systems.
PXE Boot Ideal for zero-touch deployment. Complex setup, limited reuse on running systems. New/reinstall systems.

Using these methods requires careful planning, script testing, and reliable error handling and logging mechanisms. Version control of scripts is also critical.