puppet basic info - nil41/puppet GitHub Wiki
Puppet:- 4.x
Automation tool————————-
-Puppet Labs
-Linux, Windows, Mac
-Ruby
-
-client server architecture
puppet master (server) and puppet agent (client)
-one or more puppet master over network
it requires NTP for synchronization.—————————
-
-8140 port
default 30m (change it by “runinterval =5m” >> puppet.conf)——————
-
PKG:-
apt-get install puppet # On clients (nodes)
apt-get install puppetmaster # On server (master)
yum install puppet # On clients (nodes)
yum install puppet-server # On server (master)
-———————
SRV:-
puppetmaster →master————————
-puppet →agent
-
configuration file:- on all hosts
/etc/puppet/puppet.conf
dns name———————————-
-cert
-server address //need to mention at agent side
-
mainifest file:- //master
/etc/puppet/mainifest/site.pp
//where we write code (resources)
-—————————————
to push config from master:-
#puppet apply filename.pp OR #service puppetmaster restart
-—————————————
to trigger config from agent:-
#puppet agent -test OR #puppet agent -t—————————————
-
default time to read mainifest file from agent is 30m—————————————
-
resources type:- package, service, file, user, mount, exec …
node ‘hostname1’,‘hostname2’ {
resources_type { ‘title’:
argument => value,
other_arg => value,
}
}
node default{
}
-——————————————-
e.g.1:-
#vim site.pp
node ‘agent_hostname’ {
file{ ‘/etc/test’: //first check file is present if not creates file
content => “this is test file”,
}
}
-———————————————————-
e.g.2:-
user { ‘testuser’:
ensure => present,
uid => ‘1000’,
gid => ‘1000’,
shell => ‘/bin/bash’,
home => ‘/home/testuser’
}
e.g.3:-
Installation of OpenSSH package
package { ‘openssh’:
ensure => present, //absent for uninstall
}
-————————————-
e.g.4:-
Start of httpd service
service { ‘httpd’:
ensure => running,
enable => true,
}
file { ‘resource title’:
path => # The path to the file to manage.
ensure => # Whether the file should exis.present/absent/file/directory/link
backup => # Whether (and how) file content should be backed…
content => # The desired contents of a file, as a string…
force => # Perform the file operation even if it will…
group => # Which group should own the file. Argument can…
mode => # The desired permissions mode for the file, in…
owner => # The user to whom the file should belong….
source => # A source file, which will be copied into place…
source_permissions => # Whether Puppet should copy owner permission.use/ignore
target => # if ensure=>link then target=>path to original link.
}
package { ‘resource title’:
provider => # apt-get/dpkg/rpm/yum/undef
ensure => # present/installed/absent/purge/latest
}
Executing commands:-
exec { ‘get_my_file’:
command => "wget http://mysite/myfile.tar.gz -O /tmp/myfile.tar.gz’,
path => ‘/sbin:/bin:/usr/sbin:/usr/bin’,
# A file created by the command. It if exists, the command is not executed
creates => ‘/tmp/myfile.tar.gz’,
- A command or an array of commands, if any of them returns an error
- the command is not executed
onlyif => ‘ls /tmp/myfile.tar.gz && false’,
- A command or an array of commands, if any of them returns an error
- the command IS executed
unless => ‘ls /tmp/myfile.tar.gz’,
}
to install apache/http on diff linux distro:
if $::osfamily == ‘Debian’ {
$package_name = ‘apache2’
}
elsif $::osfamily == ‘RedHat’ {
$package_name = ‘httpd’
} else
{
notify { “Operating system $::operatingsystem not supported” }
}
ensure => present,
}
dependancies:
// ensure apache2 service is running
service { ‘apache2’:
ensure => running,
}
=========
resources:- package, service, file, user, mount, exec …
classes:- collection of resources
mainifest:- collection of classes and resources
modules:- collection of mainifests
==========
Classes are containers of different resources.
class mysql (
root_password => ‘default_value’,
port => ‘3306’,
) {
package { ‘mysql-server’:
ensure => present,
}
service { ‘mysql’:
ensure => running,
}
}
When we have to use a class previously defined, we declare it.
This can be done in 2 different ways:
without parameters:
include mysql
class declaration with explicit parameters:
class { ‘mysql’:
root_password => ‘my_value’,
port => ‘3307’,
}
==========
The following is the puppet manifest directory structure:
/manifests/classes/ – Directory containing all classes
/manifests/site.pp – the primary manifest file
/manifests/templates.pp – Contains template nodes
/manifests/nodes.pp – Contains node definitions
/manifests/definitions/ – Contains all definitions
/manifests/groups/ – Contains manifests configuring groups
/manifests/os/ – Contains classes designed to configure nodes with particular operating systems
/manifests/users/ – Contains manifests configuring users
/manifest/files/ – Contains file server modules for Puppet distributable files
============