0

I need to validate agent like memory, processor, and port connectivity before running my other manifest files. So I've created a manifest like following by keeping global facts with and statement and exec resource.

class vc {
#Validateing Infra Before applying chnages
if $::facts['memorysize'] >= '4.00 GiB'and $::facts['processorcount'] >= 2 and Exec['port_connectivity'] {
  notify { "Infra validated" : }
  include vc::configs 
}
else {
  notify { "Infra not meeting requirements" : }
} 
# Checking port connecitivity to puppet master  
exec { 'port_connectivity':
  command   => 'New-Item c:\debug.txt -type file -Force',
  unless    => 'if((New-Object System.Net.Sockets.TcpClient ("linux-NAS-storage.com",6163)).connected -eq $true) { exit 1 }',
  provider  => powershell,
  }  
}

my theme is puppet should only execute if this if $::facts['memorysize'] >= '4.00 GiB'and $::facts['processorcount'] >= 2 and Exec['port_connectivity'] condition was successful. If exec command was successful and facter returns true then only it should execute, but following manifest executing individually without checking whether that exec statement true or not. My main purpose I need to validate ports before running puppet manifest. Can any please help

Dev
  • 371
  • 1
  • 4
  • 19
  • You should make the port connectivity a custom fact and also switch those conditionals over to auto Hiera class includes. The length of the answer for how to do all that is a bit much for Stack Overflow, but there is plenty of documentation at Puppet to help. – Matthew Schuchard Oct 03 '16 at 16:54
  • @MattSchuchard Thanks but can you share a sample snippet if possible – Dev Oct 03 '16 at 17:13
  • The connection check is pointless. Just remove it. If the Puppet agent is unable to contact the master it will throw an error anyway, and without being contacted by the agent first the master won't compile a catalog. – Ansgar Wiechers Oct 03 '16 at 18:28
  • It's True @AnsgarWiechers bt basically I need to test port connectivity – Dev Oct 03 '16 at 18:55
  • 2
    @Dev, you seem to be missing the point. The agent connecting to the master to issue a catalog request inherently serves as a connection test, provided that you configure the agent not to use cached catalogs. An explicit test is redundant, because Puppet will perform a catalog run only if it has already demonstrated that it can connect. – John Bollinger Oct 03 '16 at 19:05
  • Oh I didn't even look at what the connectivity test was doing. @JohnBollinger is completely correct. That test is redundant. – Matthew Schuchard Oct 03 '16 at 19:06
  • @MattSchuchard ,John My intention is not test puppet master connectivity from agent, I have set of services like NAS Connection, REST APi Port connection, VDS Port connection..etc , I just need to test whether those ports are opened at agent level before running manifest, As my manifest code will depend on those services – Dev Oct 03 '16 at 20:08

0 Answers0