Friday, February 15, 2019

Easy Puppet Templates

I could not find a simple example to get me started with puppet's templating feature. It turns out that it's a lot easier than you'd think but all I could find was super detailed instructions. So if you're looking for an easy working example, give this a try. Otherwise, there's other more complex and detailed instructions out there.

This module manages check_mk.ini on windows server. Sometimes, you might have the need to have a different check on a specific windows server.

Structure:
- modules (your root module directory)
  - mymodule (your module directory)
    - template (create this directory to hold your template file)
      - check_mk.ini.epp (create this file. It is your template.)

The contents of check_mk.ini.epp:
#check_mk.ini:
# Managed by puppet
# any changes will be reverted
#
[mrpe]
    # Run classical monitoring plugins. The word before the command
    # line is the service description for the monitoring. Use backslashes
    # in Windows-paths.
    # check = Dummy mrpe\check_crit
    # check = IP_Configuration mrpe\check_ipconfig 1.2.3.4
    # check = Whatever c:\myplugins\check_whatever -w 10 -c 20
    #
<%# This is a comment %>
<%- if $facts[fqdn] == "myserver01.mydomain.com" { -%>
    check = Report_Server c:\plugins\check_report.bat
<% } -%>
<%- if $facts[fqdn] == "myserver02.mydomain.com" { -%>
    check = Report_Server c:\sbin\check_old_report.bat
<% } -%>

    check = guest_user c:\plugins\check_guestuser.bat

Explanation of the check_mk.ini.epp file:
if your server's fully qualified domain name is myserver01.mydomain.com, then add the line:
check = Report_Server c:\plugins\check_report.bat

otherwise

if your server's fully qualified domain name is myserver02.mydomain.com, then add the line:
 check = Report_Server c:\sbin\check_old_report.bat

always add the following line because it's not constrained by any 'if' statements:
 check = guest_user c:\plugins\check_guestuser.bat

What's inside the manifest:

    file { "C:\\Program Files (x86)\\check_mk\check_mk.ini":
      ensure  => file,
      content => epp('mymodule/check_mk.ini.epp'),
    }

Troubleshooting:
If puppet isn't recognizing your facts, run "facter" at the command prompt. Look at your fact. Does it look exactly as you typed?
Example: 
If facter says
fqdn => "myserver01.mydomain.com"
then, use "myserver01.mydomain.com"

otherwise, if facter says
fqdn => myserver01.mydomain.com
then, use myserver01.mydomain.com

Summary:
As you can see, it's pretty simple. Hopefully, this will get you going and then, reading the more indepth docs/tutorials will make more sense.

Sylink:(EXCEPTION, err=2) AH: failed to send request...

Symantec Endpoint Protection Client started failing to update its anti-virus definition. After enabling debug logging, all I can see is:

Sylink:(EXCEPTION, err=2) AH: failed to send request...

I launched wireshark and I see no communication errors. I rebooted the server to no avail. Then, I did some tinkering and for whatever reason, it started working. I don't know what exactly fixed it but here you go:

1) run smc.exe -stop
2) run smc.exe -start
3) Launch Symantec Endpoint Protection
4) in the tray icon, right click the symantec icon and click 'Disable Symantec Endpoint Protection'
5) wait a few seconds and the client UI will turn red and tell you that everything is disabled
6) click Fix All and wait
7) in a few seconds, the client UI will go back to being orange
8) click Fix
9) go look at the debug log and you won't see anymore errors
10) in a few minutes, the client UI will turn green