=========== Puppet practice on Centos ===========
[root@puppetmaster modules]$ cd /etc/puppetlabs/code/environments/production/manifests/
[root@puppetmaster manifests]$ ls
[root@puppetmaster manifests]$ vi hello.pp
[root@puppetmaster manifests]$ cat hello.pp
notify {'Hello World':}
[root@puppetmaster manifests]$
================================================================================================
** If want to apply above on puppet server then use following command on puppet server
[root@puppetmaster manifests]$ puppet apply hello.pp
Notice: Compiled catalog for puppetmaster.localdomain in environment production in 0.02 seconds
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.01 seconds
** If want to apply on puppet client to client then use following command on puppet server
[root@webprd1 ~]$ puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538057264'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.03 seconds
[root@webprd1 ~]$
********* now we are using file resource type *********
[root@puppetmaster manifests]$ vi demo.pp
[root@puppetmaster manifests]$ cat demo.pp
file {'/tmp/demo.txt':
ensure => present,
content => 'Hello linuxchamps users',
}
[root@webprd1 ~]$ puppet agent -t --noop <----------------if you want to check what are new changes going to apply on client use noop this is dry run
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Applying configuration version '1538057956'
Notice: /Stage[main]/Main/File[/tmp/demo.txt]/ensure: current_value 'absent', should be 'present' (noop) <------ its saying /tmp/demo.txt is absent should be present
Notice: /Stage[main]/Main/Notify[Hello World]/message: current_value 'absent', should be 'Hello World' (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 event
Notice: Applied catalog in 0.02 seconds
[root@webprd1 ~]$
[root@webprd1 ~]$ ll /tmp/demo.txt
ls: cannot access /tmp/demo.txt: No such file or directory <------- Currenlty file is not present
[root@webprd1 ~]$ puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538058210'
Notice: /Stage[main]/Main/File[/tmp/demo.txt]/ensure: defined content as '{md5}18a8acba178a037b8f1895c04eaf7387' <--- file is created
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.11 seconds
[root@webprd1 ~]$
[root@webprd1 ~]$ cat /tmp/demo.txt <------------ file is present at client side
Hello linuxchamps users
========== Now lets try to change file permissons ========
[root@puppetmaster manifests]$ cat demo.pp
file {'/tmp/demo.txt':
ensure => present,
content => 'Hello linuxchamps users',
mode => '774'
}
[root@webprd1 ~]$ ll /tmp/demo.txt <-------- current permissons for /tmp/demo.txt
-rw-r--r--. 1 root root 23 Sep 27 19:53 /tmp/demo.txt
[root@webprd1 ~]$ puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538058581'
Notice: /Stage[main]/Main/File[/tmp/demo.txt]/mode: mode changed '0644' to '0774' <------- File permissons has been changed from 644 to 774
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.02 seconds
[root@webprd1 ~]$
[root@webprd1 ~]$ ll /tmp/demo.txt
-rwxrwxr--. 1 root root 23 Sep 27 19:53 /tmp/demo.txt
[root@webprd1 ~]$
======== Lets see user creation via puppet =======
[root@puppetmaster manifests]$ cat user.pp
user { 'anuj':
ensure => 'present',
gid => '501',
home => '/home/anuj',
password => '!!',
password_max_age => '99999',
password_min_age => '0',
shell => '/bin/bash',
uid => '501',
}
group { 'appuser':
gid => '501',
}
file { "/home/anuj":
ensure => directory,
owner => anuj,
group => appuser,
mode => '0750'
}
[root@webprd1 ~]$ grep -i anuj /etc/passwd <-------- on Puppet agent user anuj is not present
[root@webprd1 ~]$
[root@webprd1 home]$ grep -i appuser /etc/group
[root@webprd1 home]$ puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538064313'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: /Stage[main]/Main/Group[appuser]/ensure: created <--------------- group appuser created
Notice: /Stage[main]/Main/User[anuj]/ensure: created <--------------- user anuj created
Notice: /Stage[main]/Main/File[/home/anuj]/ensure: created <--------------- home directory created for user anuj
Notice: Applied catalog in 0.19 seconds
[root@webprd1 home]$
[root@webprd1 home]$ grep -i anuj /etc/passwd
anuj:x:501:501::/home/anuj:/bin/bash
[root@webprd1 home]$
[root@webprd1 home]$ grep -i appuser /etc/group
appuser:x:501:
[root@webprd1 home]$ su - anuj
-bash-4.2$
================= lets try to install package via puppet on client ==============
[root@puppetmaster manifests]$ vi /etc/puppetlabs/code/environments/production/manifests/package.pp
package {'httpd':
ensure => present,
name => 'httpd'
}
service {'httpd':
ensure => running,
enable => true,
}
*** have a look httpd package is not present on client at this mommnet <==========
[root@webprd1 puppet]$ yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.nbrc.ac.in
* epel: mirror1.ku.ac.th
* extras: mirrors.fibergrid.in
* updates: mirrors.fibergrid.in
Available Packages
httpd.x86_64 2.4.6-80.el7.centos.1 updates
[root@webprd1 puppet]$ puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538096426'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: /Stage[main]/Main/Package[httpd]/ensure: created <======================== httpd package has been installed
Notice: /Stage[main]/Main/Service[httpd]/ensure: ensure changed 'stopped' to 'running' <================= httpd service has been started
Notice: /Stage[main]/Main/Service[httpd]/enable: enable changed 'false' to 'true' <================ httpd service has been added at startup
Info: /Stage[main]/Main/Service[httpd]: Unscheduling refresh on Service[httpd]
Notice: Applied catalog in 84.98 seconds
[root@webprd1 ~]$ ps -ef | grep -i yum
root 15177 15089 10 06:30 ? 00:00:09 /usr/bin/python /usr/bin/yum -d 0 -e 0 -y install httpd <=========== backend it call yum to install httpd
root 15345 15211 0 06:31 pts/3 00:00:00 grep --color=auto -i yum
[root@webprd1 ~]$
[root@webprd1 ~]$
[root@webprd1 ~]$ ps -ef | grep -i yum
root 15391 15211 0 06:31 pts/3 00:00:00 grep --color=auto -i yum
[root@puppetmaster modules]$ cd /etc/puppetlabs/code/environments/production/manifests/
[root@puppetmaster manifests]$ ls
[root@puppetmaster manifests]$ vi hello.pp
[root@puppetmaster manifests]$ cat hello.pp
notify {'Hello World':}
[root@puppetmaster manifests]$
================================================================================================
** If want to apply above on puppet server then use following command on puppet server
[root@puppetmaster manifests]$ puppet apply hello.pp
Notice: Compiled catalog for puppetmaster.localdomain in environment production in 0.02 seconds
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.01 seconds
** If want to apply on puppet client to client then use following command on puppet server
[root@webprd1 ~]$ puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538057264'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.03 seconds
[root@webprd1 ~]$
********* now we are using file resource type *********
[root@puppetmaster manifests]$ vi demo.pp
[root@puppetmaster manifests]$ cat demo.pp
file {'/tmp/demo.txt':
ensure => present,
content => 'Hello linuxchamps users',
}
[root@webprd1 ~]$ puppet agent -t --noop <----------------if you want to check what are new changes going to apply on client use noop this is dry run
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Applying configuration version '1538057956'
Notice: /Stage[main]/Main/File[/tmp/demo.txt]/ensure: current_value 'absent', should be 'present' (noop) <------ its saying /tmp/demo.txt is absent should be present
Notice: /Stage[main]/Main/Notify[Hello World]/message: current_value 'absent', should be 'Hello World' (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 2 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 event
Notice: Applied catalog in 0.02 seconds
[root@webprd1 ~]$
[root@webprd1 ~]$ ll /tmp/demo.txt
ls: cannot access /tmp/demo.txt: No such file or directory <------- Currenlty file is not present
[root@webprd1 ~]$ puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538058210'
Notice: /Stage[main]/Main/File[/tmp/demo.txt]/ensure: defined content as '{md5}18a8acba178a037b8f1895c04eaf7387' <--- file is created
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.11 seconds
[root@webprd1 ~]$
[root@webprd1 ~]$ cat /tmp/demo.txt <------------ file is present at client side
Hello linuxchamps users
========== Now lets try to change file permissons ========
[root@puppetmaster manifests]$ cat demo.pp
file {'/tmp/demo.txt':
ensure => present,
content => 'Hello linuxchamps users',
mode => '774'
}
[root@webprd1 ~]$ ll /tmp/demo.txt <-------- current permissons for /tmp/demo.txt
-rw-r--r--. 1 root root 23 Sep 27 19:53 /tmp/demo.txt
[root@webprd1 ~]$ puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538058581'
Notice: /Stage[main]/Main/File[/tmp/demo.txt]/mode: mode changed '0644' to '0774' <------- File permissons has been changed from 644 to 774
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: Applied catalog in 0.02 seconds
[root@webprd1 ~]$
[root@webprd1 ~]$ ll /tmp/demo.txt
-rwxrwxr--. 1 root root 23 Sep 27 19:53 /tmp/demo.txt
[root@webprd1 ~]$
======== Lets see user creation via puppet =======
[root@puppetmaster manifests]$ cat user.pp
user { 'anuj':
ensure => 'present',
gid => '501',
home => '/home/anuj',
password => '!!',
password_max_age => '99999',
password_min_age => '0',
shell => '/bin/bash',
uid => '501',
}
group { 'appuser':
gid => '501',
}
file { "/home/anuj":
ensure => directory,
owner => anuj,
group => appuser,
mode => '0750'
}
[root@webprd1 ~]$ grep -i anuj /etc/passwd <-------- on Puppet agent user anuj is not present
[root@webprd1 ~]$
[root@webprd1 home]$ grep -i appuser /etc/group
[root@webprd1 home]$ puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538064313'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: /Stage[main]/Main/Group[appuser]/ensure: created <--------------- group appuser created
Notice: /Stage[main]/Main/User[anuj]/ensure: created <--------------- user anuj created
Notice: /Stage[main]/Main/File[/home/anuj]/ensure: created <--------------- home directory created for user anuj
Notice: Applied catalog in 0.19 seconds
[root@webprd1 home]$
[root@webprd1 home]$ grep -i anuj /etc/passwd
anuj:x:501:501::/home/anuj:/bin/bash
[root@webprd1 home]$
[root@webprd1 home]$ grep -i appuser /etc/group
appuser:x:501:
[root@webprd1 home]$ su - anuj
-bash-4.2$
================= lets try to install package via puppet on client ==============
[root@puppetmaster manifests]$ vi /etc/puppetlabs/code/environments/production/manifests/package.pp
package {'httpd':
ensure => present,
name => 'httpd'
}
service {'httpd':
ensure => running,
enable => true,
}
*** have a look httpd package is not present on client at this mommnet <==========
[root@webprd1 puppet]$ yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.nbrc.ac.in
* epel: mirror1.ku.ac.th
* extras: mirrors.fibergrid.in
* updates: mirrors.fibergrid.in
Available Packages
httpd.x86_64 2.4.6-80.el7.centos.1 updates
[root@webprd1 puppet]$ puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for webprd1.localdomain
Info: Applying configuration version '1538096426'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: /Stage[main]/Main/Package[httpd]/ensure: created <======================== httpd package has been installed
Notice: /Stage[main]/Main/Service[httpd]/ensure: ensure changed 'stopped' to 'running' <================= httpd service has been started
Notice: /Stage[main]/Main/Service[httpd]/enable: enable changed 'false' to 'true' <================ httpd service has been added at startup
Info: /Stage[main]/Main/Service[httpd]: Unscheduling refresh on Service[httpd]
Notice: Applied catalog in 84.98 seconds
[root@webprd1 ~]$ ps -ef | grep -i yum
root 15177 15089 10 06:30 ? 00:00:09 /usr/bin/python /usr/bin/yum -d 0 -e 0 -y install httpd <=========== backend it call yum to install httpd
root 15345 15211 0 06:31 pts/3 00:00:00 grep --color=auto -i yum
[root@webprd1 ~]$
[root@webprd1 ~]$
[root@webprd1 ~]$ ps -ef | grep -i yum
root 15391 15211 0 06:31 pts/3 00:00:00 grep --color=auto -i yum
No comments:
Post a Comment