R. Patel
R. Patel

Reputation: 49

Install Puppet Agent on bulk windows server

Is there any way to install Puppet Agent on bulk Windows server?

To achieve this I have created small PowerShell script, but not working as expected.

$computers = Get-Content "C:\server.txt"
$pm_ip = '10.xx.xx.xx'
$port = '8140'

foreach ($computer in $computers) {
    $ErrorActionPreference = "SilentlyContinue"
    Set-ExecutionPolicy -Scope Process -ExecutionPolicy AllSigned
    [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; 
    $webClient = New-Object System.Net.WebClient; 
    $webClient.DownloadFile("https://downloads.puppetlabs.com/windows/puppet- 
    agent-5.5.3-x64.msi"); 
    extension_requests:pp_role=utility extension_requests:pp_environment=e1 
    agent:noop=true

    Write-Host "$($_.ServerName) was configured" -BackgroundColor 00 -ForegroundColor 10
}

Upvotes: 0

Views: 884

Answers (2)

Thirumoorthi
Thirumoorthi

Reputation: 518

use puppet bolt Please click on the link to check out what puppet code is, and @ansgar-wiechers , it is an simplest one , and puppet enterprise also comes with and powershell

https://puppet.com/docs/pe/2017.3/installing_agents.html#installing-windows-agents

Please check this link for how to use powershell script to installing windows agent in a single node, but you have to use install it in multiple nodes, here comes puppet bolt for the help.

https://puppet.com/products/puppet-bolt

main thing we have to note here is as mentioned below,

Agentless

Just connect remotely to a device via SSH or WinRM and execute commands on any supported platform. No agents needed, only keypair or password credentials. Bolt cleans up after itself, too!

below link helps you to 'how to run puppet bolt commands'

https://puppet.com/docs/bolt/0.x/running_bolt_commands.html

before this you have to setup an inventory file , which contains all the nodes you have to add to puppet master.

hope this helps you to solve

Upvotes: 1

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200573

For one thing, there are several syntactical errors in the code you posted. If you wrap a string like this:

"https://downloads.puppetlabs.com/windows/puppet- 
   agent-5.5.3-x64.msi"

the server won't recognize the file. Also, the following lines are not valid PowerShell code:

extension_requests:pp_role=utility extension_requests:pp_environment=e1 
agent:noop=true

The main issues with your code, however, are these:

  • Your URL is wrong. The Puppet 5 client are located under /windows/puppet5, not directly under /windows like the older clients are.
  • The DownloadFile() method expects at least 2 parameters: the URL and the output filename.

Change your code to this:

$client = 'puppet-agent-5.5.3-x64.msi'
$url    = "https://downloads.puppetlabs.com/windows/puppet5/${client}"
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$webClient = New-Object Net.WebClient
$webClient.DownloadFile($url, $client)

and it should download the client installer to the current working directory.

Also, running a loop for each server doesn't magically run the code on the servers. You need to write code to actually connect to the servers and run something there. Download the installer just once, then copy the MSI to all of your servers and invoke it remotely:

Invoke-Command -Computer $computers -Scriptblock {
    & msiexec 'C.\path\to\puppet-agent.msi' /qn /l*v 'C:\puppet_install.log'
}

Upvotes: 1

Related Questions