Skip to content

Instantly share code, notes, and snippets.

View rafalf's full-sized avatar

Rafal Fusik rafalf

  • freelancer
  • Dublin
View GitHub Profile
@rafalf
rafalf / puppet.ps1
Last active May 12, 2016 08:33
puppet: install puppet and its modules using Powershell (bootstrapping using Powershell)
# install puppet
$msiArgumentList = "/qn /i C:\FolderName\puppet-enterprise-3.2.0.msi /l*v C:\install_puppet.log"
Start-Process -FilePath msiexec.exe -ArgumentList $msiArgumentList -Wait
# add puppet to path
$SetPath = $env:Path + ";C:\Program Files (x86)\Puppet Labs\Puppet Enterprise\bin\"
[Environment]::SetEnvironmentVariable("Path", "$SetPath", "Machine")
# Reload path ( in order to install modules )
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
@rafalf
rafalf / readuserdatascript.py
Last active August 29, 2015 14:01
puppet/aws: reading userdata powershell script, wrapping in <powershell> tags and setting environment variables
def _read_script(self, script_name, site_name, type):
script = ""
script += "<powershell>\n\n"
# set environment variable
script += " [Environment]::SetEnvironmentVariable(\"ENVNAME\", \"" + site_name + "\", \"Machine\")\n"
script += " [Environment]::SetEnvironmentVariable(\"NTPSERVER\", \"ntp." + site_name + "\", \"Machine\")\n"
script += " [Environment]::SetEnvironmentVariable(\"PREPDIR\", \"C:\\AmazonEnvPrep-v2012\", \"Machine\")\n"
@rafalf
rafalf / init.pp
Created May 20, 2014 13:58
puppet: install app tier packages
class install_app_utilities {
package { 'install java':
ensure => '7.51',
source => 'C:\Prepfolder\3rdParty\Java\jre-7u51-windows-x64.exe',
install_options => ['/s']
}
package { 'install membase':
@rafalf
rafalf / init.pp
Created May 20, 2014 14:01
puppet: install OS packages
class install_utilities {
package { 'install python':
ensure => '2.7.2.5',
source => 'C:\Prepfolder\3rdParty\Python\ActivePython-2.7.2.5-win64-x64.msi',
install_options => ['/quiet']
}
package { 'install notepad':
@rafalf
rafalf / init.pp
Created May 20, 2014 14:03
puppet: install web tier IIS modules
class install_web_utilities {
require web_config # It requires web_config class to be executed prior to installing IIS Modules
package { 'install rewrite':
ensure => '2.0',
source => 'C:\Prepfolder\3rdParty\IISModules\rewrite_2.0_rtw_x64.msi',
install_options => ['/quiet']
}
@rafalf
rafalf / init.pp
Created May 20, 2014 14:08
puppet: execute web_config.ps1 powershell script.
class web_config{
# c:\windows\sysnative\windowspowershell\v1.0\powershell.exe - forces 64-bit PS
# https://tickets.puppetlabs.com/browse/MODULES-953
exec { 'exec web_config.ps1':
command => 'c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -executionpolicy remotesigned -file C:\ProgramData\PuppetLabs\puppet\etc\modules\web_config\manifests\web_config.ps1',
logoutput => true,
timeout => 1800,
}
@rafalf
rafalf / logger.ps1
Last active August 28, 2016 15:15
Logger function
#
# powershell logger function
#
function log ([string]$logdata)
{
$date = get-date
Write-Output "$date - $logdata" | Out-File $log -width 240 -Append
}
log "Script started"
@rafalf
rafalf / manifest.pp
Created February 17, 2015 15:04
puppet: executing manifests conditioned by $envtype facter (system env variable: FACTER_envtype)
if $envtype == 'distributed_prod'
{
include app_config
include install_newrelic_server
include dns_suffix_prod
include install_sts_prod
include grant_cert_perm_prod
include task_windows_time
}
elsif $envtype == 'distributed_test'
@rafalf
rafalf / testUserCredentials.ps1
Last active August 28, 2016 15:14
Test windows user credentials
#
# Returns True if Password matches, False otherwise
#
Function Test-UserCredential {
Param($username, $password)
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Machine, $env:computername
$opt = [System.DirectoryServices.AccountManagement.ContextOptions]::SimpleBind
$pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ct
$Result = $pc.ValidateCredentials($username, $password).ToString()
@rafalf
rafalf / sendEmailAws.py
Last active September 9, 2016 19:26
Send Email - Amazon SES SMTP Endpoint (TLS)
#
# to send emails via Amazon SES SMTP (TLS)
#
def sendMail(self, subject, email_content):
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email import Encoders