Shiva

Modify webconfig connectionstring using powershell


 [CmdletBinding()]
  param ($PT_connectionstring_new =  "newpassword")  
  $webConfig = 'D:\Web.config'

Function updateWebConfig($config) 
{ 
$doc = (Get-Content $config) -as [Xml]
$root = $doc.get_DocumentElement();
$activeConnection = $root.connectionStrings.SelectNodes("add")|?{$_.name -eq "PROD"};
$activeConnection.SetAttribute("connectionString",$PT_connectionstring_new);
$doc.Save($config)
} 

updateWebConfig($webConfig)

IIS Authentication info using puppet

iis_application { 'myapp':
  ensure             => 'present',
  sitename           => 'mysite',
  physicalpath       => 'C:\\inetpub\\app',
  authenticationinfo => {
    'basic'     => true,
    'anonymous' => false,
  },
}

Download remote zip, extract zip and copy files using puppet in windows

#download file from repo
 download_file { 'Download dotnet 4.0' :
  url                   => 'https://repos.shivaprogramming.com/Myapp.ZIP',
  destination_directory => 'D:\downloadapp',
}

#extract zip
 exec { 'Unzip Folder':
        command =>'Expand-Archive -Path D:\downloadapp\Myapp.ZIP -DestinationPath D:\downloadapp\DEST',
        provider  => powershell,
        logoutput =>    true,
        subscribe => Download_file['Download dotnet 4.0'],
    } 
#copy resources to the destination
 
 file { 'D:\CA_Websites\MyApp':  #destination
 ensure    => 'directory',
 recurse   => true,
 source    => 'D:\downloadapp\DEST',
 subscribe => Exec['Unzip Folder'],
  }


Install IIS using puppet code

# copy IIS files into inetpub folder
file { 'C:\\inetpub\\minimal\\' :
ensure  => 'directory',
source  => 'C:\\moveto\\ACME',
recurse => true,
}

#create  application pool
iis_application_pool { 'ACME':
  ensure                  => 'present',
  state                   => 'started',
  managed_pipeline_mode   => 'Integrated',
  managed_runtime_version => 'v4.0',
} ->

# create Default Website
iis_site { 'Default Web Site':
  ensure          => 'started',
  #physicalpath    => 'C:\\inetpub',
  applicationpool => 'ACME',
} ->
#create IIS  application 
iis_application {'ACME':
  ensure          => present,
  applicationname => 'ACME', # <-- Does not need to match the title
  sitename        => 'Default Web Site',
  physicalpath => 'C:\\inetpub\\minimal',
} ->
#create IIS application  and convert to application
iis_application{'/ACME/UI':
  applicationpool => 'ACME',
  ensure          => 'present',
  sitename        => 'Default Web Site',
physicalpath => 'C:\\inetpub\\minimal\\UI'
}

Docker commands

docker ps -> List all the running docker processes. ps means the process starts

docker run hello-world => docker run image name

docker run – p 80:80 nginx

80:80=> Port 80 on host and port 80 container

nginx is a web server running on port 80

docker stop – container id

docker start container name

Create docker image

# Sample of docker file
# Use a container with Go pre-installed
FROM quay.io/projectquay/golang:1.17

# Copy our source file into the container
COPY src/hello-world.go /go/hello-world.go

# Set the default environment variables
ENV MESSAGE "Welcome! You can change this message by editing the MESSAGE environment variable."
ENV HOME /go

# Set permissions to the /go folder (for OpenShift)
RUN chgrp -R 0 /go && chmod -R g+rwX /go

# Just documentation.
# This container needs Docker or OpenShift to help with networking
EXPOSE 8080

# OpenShift picks up this label and creates a service
LABEL io.openshift.expose-services 8080/http

# OpenShift uses root group instead of root user
USER 1001

# Command to run when container starts up
CMD go run hello-world.go
docker build .

# . current directory
show list of images => docker images

Tag docker image

docker build -t shiva:v1 .

Check the Status of a docker image

docker ps   
#  show the running container check the status field

Remove the image

docker rmi image name

Adding port

# -p (host port):(container port)
docker run -it  -p 8080:8080  quay.io/practicalopenshift/hello-world

Running the docker help page offline

docker run -p 4000:4000 docs/docker.github.io

Add name and run interactive mode

docker run -p 4000:4000 -it --name shivadoc docs/docker.github.io

Find more info about container

docker inspect (container name or ID)
you can find the ip address of the container

Stop all the container

docker ps-q
docker stop $(docker ps -q)

Remove all the containers

docker ps -aq
docker rm $(docker ps-aq)
docker image prune 
docker volume ls
docker volume ls -f dangling=true

Deploy to Private Registry

docker run -d -p 1000:1000 -name regsitry register:version

docker image tag my-imagename localhost:1000/my-imagename

docker push localhost:1000/my-imagename

docker pull localhost:1000/my-imagename

dpocker pull 192.168.1.1:1000/my-imagename

Install Oracle client using rsp file ,powerShell and puppet

Create a ps1 file for eg oracleclientInstall.ps1

#oracelclientInstall.ps1
cmd.exe
C:\MyTemp\Ora11gx32\setup.exe -responseFile "C:\MyTemp\Ora11gx32\response\runtime.rsp" -silent
exit

Calling powershell file via Puppet exec resource

#Installoracel.pp
exec { 'RegisterOracle':
  command   => file('C:\Temp\installoracleclientruntime.ps1'),
  provider  => powershell,
  logoutput => true,
}

puppet agent -t Installoracle.pp

exec{'oracle':
command  => "setup.exe -silent -responseFile E:/software/Win64_120102_client/client12c_64.rsp ",
path  => 'c:\apps',
 }

Run PS file using puppet exec command

in registerDLL.ps1 file

#registerDLL.ps1
$location=Set-Location -Path C:\Windows\SysWOW64
regsvr32.exe "C:\ProgramFiles(x86)_shiva\HashMgr\HashMgr.dll"

exec { 'RegisterDll':
  command   => file('C:\Temp\puppetcode\registerDLL.ps1'),
  provider  => powershell,
  logoutput => true,
}

Enable IIS AnonymousAuthentication using exec and puppet

exec{‘set-anon-auth’:
command => ‘Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/AnonymousAuthentication -name Enabled -Value True -location mysite’,
provider => ‘powershell’,
logoutput => true
}

Install exe file using puppet

package { “Access Database Engine Component”:
ensure => installed,
source => ‘C:\shivaTemp\AccessDatabaseEngine.exe’,
install_options => [ ‘/passive’, { ‘INSTALLDIR’ => ‘C:\shivaTemp’ } ],
}

$install_dir = ‘C:\shivaTemp’
package { “Access Database Engine Component”:
ensure => installed,
provider => ‘windows’,
source => ‘C:\shivaTemp\AccessDatabaseEngine.exe’,
install_options => [ ‘/passive’, { ‘INSTALLDIR’ => $install_dir } ],

}

puppet code for windows environment?

Building blocks of Puppet

  1. Resources
  2. Classes
  3. Manifest
  4. Modules

Install Puppet Windows Module Pack

puppet module install puppetlabs/windows

puppet module list

How to copy directory and it’s files using puppet

$soure_dir=c:\temp\puppetcode\Source
$destination_dir= c:\temp\puppetcode\Destination

file { $destination_dir :
ensure  => 'directory',
source  => "file://${source_dir}",
recurse => true,
}

Copy folder and remove the original folder

$soure_dir=c:\temp\puppetcode\Source
$destination_dir= c:\temp\puppetcode\Destination

file { $destination_dir :
ensure  => 'directory',
source  => "file://${source_dir}",
recurse => true,
before=> File[$source_dir],
}

file{$source_dir :
	ensure=>'absent',
	purge=>true,
	recurse=>,
	force=>true,

}

Simple code to copy folders

file {'/my/path':
    ensure  => 'directory',
    path    => '/my/path',
    recurse => true,
    source  => '/home/user_name/scripts',
    }

Running puppet code on different environment

puppet agent -t --environment production
puppet agent -t --environment stage
puppet agent -t --environment development

Adding git and auto deploy puppet code

git init --bare /srv/git/repos/mypuppetcode.git
git clone  /srv/git/repos/mypuppetcode.git

Add environment.conf file

moudulepath=site:modules:$basemodulepath
mainfest=mainfests/site.pp

Add working environment

puppet config print environment #Display the current environment

sudo puppet config set environment set environment dev

Create Modules

cd / etc/puppetlabs/code/environments/production/modules

sudo mkdir -p motd/{manifests,files,examples}

sudo vim motd/examples/init.pp

motd/mainfest/init.pp

class motd{
       file{'/etc/motd':
       ensure=> 'present',
       content=>file('motd/message'),
      }
}

sudo vim motd/files/message

write a content such as “Welcome to my server”

<environment> /modules

<modulename>/mainfests/init.pp

class motd{

}

content=>file(‘motd/message’) # motd/files/message

Modules Metadata

cd /etc/puppetlabs/code/environments/production/modules

sudo puppet module generate shiva/test

sudo puppet module generate shiva/test –skip-interview # skip

Create NTP module

/etc/puppetlabs/code/enviroments/production/modules

sudo mkdir -p ntp / {manifests,files,examples}

in windows

puppet module generate modules/ntp

Add puppet ACL for IIS Default App Pool

acl { 'C:\inetpub\wwwroot\uploads':
  permissions => [
   { identity => 'IIS AppPool\DefaultAppPool', rights => ['full'] }
 ],
}

Adding Registry Key Value

registry_key { 'hklm\software\mykey':
  ensure => present,
}

registry_value { 'hklm\software\mykey\value1':
  type => string,
  data => 'this is a value'
}

Configure Firewall

firewall-cmd --permanent --zone=public --add-port=8140/tcp
firewall-cmd –reload

Start/Enable puppet server

systemctl start puppetserver
systemctl enable puppetserver
systemctl status puppetserver
puppet status
netstat -anpl | grep 8140