Sunday, July 31, 2016

Creating and concatenating a file through a crontab job



kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > vi /etc/puppet/manifests/cron-file-concatenate.pp
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /etc/puppet/manifests/cron-file-concatenate.pp
cron {'cron-file-concatenate':
ensure                        =>       'present',
command                  =>       '/bin/echo "`date`" >> /var/fifteenth-minuter',
minute                       =>       ['15'],
target              =>       'root',
user                =>       'root',
}
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > ls -altr /var/fif*
ls: cannot access /var/fif*: No such file or directory
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet apply /etc/puppet/manifests/cron-file-concatenate.pp
Fact file /etc/puppet/modules/team_custom_facts/facts.d/README was parsed but returned an empty data set
Notice: Compiled catalog for kirandspuppet.eng.company.com in environment production in 0.06 seconds
Notice: /Stage[main]/Main/Cron[cron-file-concatenate]/ensure: created
Notice: Finished catalog run in 0.06 seconds
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > crontab -l
# HEADER: This file was autogenerated at Sun Nov 22 20:58:40 -0800 2015 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: cron-alarm
5 * * * * /bin/echo "Wake up!!! Wake up, it is getting late!!!"
# Puppet Name: cron-postfix
5 * * * * /usr/sbin/postsuper -d ALL; /sbin/service postfix start
# Puppet Name: cron-file-concatenate
15 * * * * /bin/echo "`date`" >> /var/fifteenth-minuter
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > date
Sun Nov 22 21:06:43 PST 2015
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > ls -altr /var/fif*
ls: cannot access /var/fif*: No such file or directory
kirandspuppet: / >
kirandspuppet: / > date
Sun Nov 22 21:14:30 PST 2015
kirandspuppet: / >
kirandspuppet: / > ls -altr /var/fif*
ls: cannot access /var/fif*: No such file or directory
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > date
Sun Nov 22 21:15:04 PST 2015
kirandspuppet: / >
kirandspuppet: / > ls -altr /var/fif*
-rw-r--r-- 1 root root 29 Nov 22 21:15 /var/fifteenth-minuter
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /var/fifteenth-minuter
Sun Nov 22 21:15:01 PST 2015
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > sleep 4000
kirandspuppet: / >
kirandspuppet: / > date
Sun Nov 22 22:21:14 PST 2015
kirandspuppet: / >
kirandspuppet: / > cat /var/fifteenth-minuter
Sun Nov 22 21:15:01 PST 2015
Sun Nov 22 22:15:01 PST 2015
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >










Extract facts from facter and store the information in a file



kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /tmp/introduce.pp
$user_name = "rahul"
notify {$user_name:}

file {'person.txt':
    path      =>  '/tmp/person.txt',
    content   =>  "User ${user_name}
              IP ${ipaddress}
              Host ${fqdn}
              OS ${operatingsystem} ${operatingsystemrelease}
              Puppet ${puppetversion}\n"
}

kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet apply /tmp/introduce.pp
Fact file /var/lib/puppet/facts.d/README was parsed but returned an empty data set
Notice: Compiled catalog for kirandspuppet in environment production in 0.06 seconds
Notice: rahul
Notice: /Stage[main]/Main/Notify[rahul]/message: defined 'message' as 'rahul'
Notice: /Stage[main]/Main/File[person.txt]/content: content changed '{md5}87d0f193cc2e5837c45b1c234512145a' to '{md5}4f5c2d828f405b431f5361738ca4d4a7'
Notice: Finished catalog run in 0.07 seconds
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /tmp/person.txt
User rahul
              IP 10.133.72.129
              Host kirandspuppet
              OS CentOS 6.5
              Puppet 3.6.2
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >








Create a user account and verify



kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /etc/passwd | grep tendulkar
kirandspuppet: / >
kirandspuppet: / > cat /etc/group | grep cricket
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > groupadd cricket
kirandspuppet: / >
kirandspuppet: / > cat /etc/group | grep cricket
cricket:x:501:
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > vi /etc/puppet/manifests/user-tendulkar.pp
kirandspuppet: / >
kirandspuppet: / > cat /etc/puppet/manifests/user-tendulkar.pp
user {'tendulkar':
ensure            =>    'present',
gid            =>    '501',
home            =>    '/home/tendulkar',
password        =>    '',
password_max_age    =>    '99999',
password_min_age    =>    '0',
shell            =>    '/bin/bash',
uid            =>    '15921',
}
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet apply /etc/puppet/manifests/user-tendulkar.pp
Fact file /etc/puppet/modules/team_custom_facts/facts.d/README was parsed but returned an empty data set
Notice: Compiled catalog for kirandspuppet.eng.company.com in environment production in 0.13 seconds
Notice: /Stage[main]/Main/User[tendulkar]/ensure: created
Notice: Finished catalog run in 0.11 seconds
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /etc/passwd | grep tendulkar
tendulkar:x:15921:501::/home/tendulkar:/bin/bash
kirandspuppet: / >
kirandspuppet: / > id tendulkar
uid=15921(tendulkar) gid=501(cricket) groups=501(cricket)
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >








Generate a greeting file



kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > vi /etc/puppet/manifests/filecreate.pp
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /etc/puppet/manifests/filecreate.pp
file { 'MCG-greeting':
path    =>    '/tmp/MCG-greeting',
ensure    =>    present,
mode    =>    647,
content    =>    "Welcome to the Melbourne Cricket Ground!!! \n",
}
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet apply /etc/puppet/manifests/filecreate.pp
Fact file /etc/puppet/modules/team_custom_facts/facts.d/README was parsed but returned an empty data set
Notice: Compiled catalog for kirandspuppet.eng.company.com in environment production in 0.06 seconds
Notice: /Stage[main]/Main/File[MCG-greeting]/content: content changed '{md5}e27dbf0786aba031f66f0bfab71be741' to '{md5}5f158044d861c60257a71e24676298cb'
Notice: Finished catalog run in 0.04 seconds
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > ls -altr /tmp/MCG*
-rw-r--rwx 1 root root 44 Nov 19 14:34 /tmp/MCG-greeting
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /tmp/MCG-greeting
Welcome to the Melbourne Cricket Ground!!!
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >








Create a user account, verify and delete



kirandspuppet: / >
kirandspuppet: / > vi /etc/puppet/manifests/user-ashokmankad.pp
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /etc/passwd | grep ashok
kirandspuppet: / >
kirandspuppet: / > cat /etc/group | grep cricket
cricket:x:501:
kirandspuppet: / >
kirandspuppet: / > cat /etc/puppet/manifests/user-ashokmankad.pp
user {'ashokmankad':
ensure            =>    'present',
gid            =>    '501',
home            =>    '/home/ashokmankad',
password        =>    '',
password_max_age    =>    '99999',
password_min_age    =>    '0',
shell            =>    '/bin/bash',
uid            =>    '12345',
}
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet apply /etc/puppet/manifests/user-ashokmankad.pp
Fact file /etc/puppet/modules/team_custom_facts/facts.d/README was parsed but returned an empty data set
Notice: Compiled catalog for kirandspuppet.eng.company.com in environment production in 0.13 seconds
Notice: /Stage[main]/Main/User[ashokmankad]/ensure: created
Notice: Finished catalog run in 0.11 seconds
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /etc/passwd | grep ashok
ashokmankad:x:12345:501::/home/ashokmankad:/bin/bash
kirandspuppet: / >
kirandspuppet: / > id ashokmankad
uid=12345(ashokmankad) gid=501(cricket) groups=501(cricket)
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > vi /etc/puppet/manifests/user-ashokmankad.pp
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /etc/puppet/manifests/user-ashokmankad.pp
user {'ashokmankad':
ensure            =>    'absent',
gid            =>    '501',
home            =>    '/home/ashokmankad',
password        =>    '',
password_max_age    =>    '99999',
password_min_age    =>    '0',
shell            =>    '/bin/bash',
uid            =>    '12345',
}
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet apply /etc/puppet/manifests/user-ashokmankad.pp
Fact file /etc/puppet/modules/team_custom_facts/facts.d/README was parsed but returned an empty data set
Notice: Compiled catalog for kirandspuppet.eng.company.com in environment production in 0.13 seconds
Notice: /Stage[main]/Main/User[ashokmankad]/ensure: removed
Notice: Finished catalog run in 0.08 seconds
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /etc/passwd | grep ashok
kirandspuppet: / >
kirandspuppet: / > id ashokmankad
id: ashokmankad: No such user
kirandspuppet: / >
kirandspuppet: / >








Generate a cronjob for wake up alarm



kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > crontab -l
no crontab for root
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > vi /etc/puppet/manifests/echo-alarm.pp
kirandspuppet: / >
kirandspuppet: / > cat /etc/puppet/manifests/echo-alarm.pp
cron {'cron-alarm':
ensure        =>    'present',
command        =>    '/bin/echo "Wake up!!! Wake up, it is getting late!!!"',
minute        =>    ['5'],
target        =>    'root',
user        =>    'root',
}
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet apply /etc/puppet/manifests/echo-alarm.pp
Fact file /etc/puppet/modules/team_custom_facts/facts.d/README was parsed but returned an empty data set
Notice: Compiled catalog for kirandspuppet.eng.company.com in environment production in 0.05 seconds
Notice: /Stage[main]/Main/Cron[cron-alarm]/ensure: created
Notice: Finished catalog run in 0.05 seconds
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > crontab -l
# HEADER: This file was autogenerated at Sun Nov 15 18:37:06 -0800 2015 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: cron-alarm
5 * * * * /bin/echo "Wake up!!! Wake up, it is getting late!!!"
kirandspuppet: / >
kirandspuppet: / >








Starting the service multipathd



kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet resource service multipathd
service { 'multipathd':
  ensure => 'stopped',
  enable => 'false',
}
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet resource service multipathd > /etc/puppet/manifests/multipathd.pp
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > chkconfig --list | grep multipath
multipathd         0:off    1:off    2:off    3:off    4:off    5:off    6:off
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /etc/puppet/manifests/multipathd.pp
service { 'multipathd':
  ensure => 'running',
  enable => 'true',
}
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet apply /etc/puppet/manifests/multipathd.pp
Fact file /etc/puppet/modules/team_custom_facts/facts.d/README was parsed but returned an empty data set
Notice: Compiled catalog for kirandspuppet.eng.company.com in environment production in 0.10 seconds
Notice: /Stage[main]/Main/Service[multipathd]/ensure: ensure changed 'stopped' to 'running'
Notice: Finished catalog run in 0.64 seconds
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > chkconfig --list | grep multipath
multipathd         0:off    1:off    2:on    3:on    4:on    5:on    6:off
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet resource service multipathd
service { 'multipathd':
  ensure => 'running',
  enable => 'true',
}
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > service multipathd status
multipathd (pid  42301) is running...
kirandspuppet: / >








Starting Postfix as a service



kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > vi /etc/puppet/manifests/cron-json.pp
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > cat /etc/puppet/manifests/cron-json.pp
cron {'cron-postfix':
ensure          =>      'present',
command         =>      '/sbin/service postfix start',
minute          =>      ['5'],
target          =>      'root',
user            =>      'root',
}
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > puppet apply /etc/puppet/manifests/cron-json.pp
Fact file /etc/puppet/modules/team_custom_facts/facts.d/README was parsed but returned an empty data set
Notice: Compiled catalog for kirandspuppet.eng.company.com in environment production in 0.05 seconds
Notice: /Stage[main]/Main/Cron[cron-postfix]/minute: minute changed '02' to '5'
Notice: Finished catalog run in 0.05 seconds
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / > while true; do date; service postfix status; sleep 20; echo ========================================; done
Wed Nov 18 14:03:21 PST 2015
master is stopped
========================================
Wed Nov 18 14:03:41 PST 2015
master is stopped
========================================
Wed Nov 18 14:04:01 PST 2015
master is stopped
========================================
Wed Nov 18 14:04:21 PST 2015
master is stopped
========================================
Wed Nov 18 14:04:41 PST 2015
master is stopped
========================================
Wed Nov 18 14:05:01 PST 2015
master is stopped
========================================
Wed Nov 18 14:05:21 PST 2015
master (pid  15586) is running...
========================================
Wed Nov 18 14:05:41 PST 2015
master (pid  15586) is running...
========================================
Wed Nov 18 14:06:01 PST 2015
master (pid  15586) is running...
^C
You have new mail in /var/spool/mail/root
kirandspuppet: / >
kirandspuppet: / >
kirandspuppet: / >