Search This Blog

Thursday, 4 March 2021

Create a symlink using puppet programming

 Task:
Create a puppet programming file apps.pp under /etc/puppetlabs/code/environments/production/manifests directory on puppet master node i.e on Jump Server. Within that define a class symlink and perform below mentioned tasks:
Create a symbolic link through puppet programming code. The source path should be /opt/data and destination path should be /var/www/html on all Puppet agents i.e on all App Servers.
Create a blank file media.txt under /opt/data directory on all puppet agent nodes i.e on all App Servers.
Note: Please perform this task using apps.pp only, do not create any separate inventory file.

Step 1) Create puppet class file apps.pp on jump host where puppet master is running

root@jump_host /# cd /etc/puppetlabs/code/environments/production/manifests
root@jump_host /etc/puppetlabs/code/environments/production/manifests# cat>apps.pp 
class symlink {
# create a symlink
 file { '/opt/data/':
      ensure => 'link',
      target => '/var/www/html',
 }
#media.txt file creation
 file { '/opt/data/media.txt':
      ensure => 'present',
      content => '',
 }
}
node 'stapp01.stratos.xfusioncorp.com', 'stapp02.stratos.xfusioncorp.com', 'stapp03.stratos.xfusioncorp.com' {
include symlink
}

Step 2) Validate the syntax 

root@jump_host /etc/puppetlabs/code/environments/production/manifests# puppet parser validate apps.pp

Step 3) Run puppet agent -tv on app server 1 and validate if the symlink and empty file is created. 

[root@stapp01 ~]# puppet agent -tv
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for stapp01.stratos.xfusioncorp.com
Info: Applying configuration version '1614862700'
Notice: /Stage[main]/Symlink/File[/opt/data/]/ensure: created
Notice: /Stage[main]/Symlink/File[/opt/data/media.txt]/ensure: defined content as '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: Applied catalog in 0.05 seconds
[root@stapp01 ~]# cd /opt/data
[root@stapp01 data]# ls -rlt
total 0
-rw-r--r-- 1 root root 0 Mar  4 12:58 media.txt
[root@stapp01 data]# cd /var/www/html/
[root@stapp01 html]# ls -rlt
total 0
-rw-r--r-- 1 root root 0 Mar  4 12:58 media.txt
[root@stapp01 html]# cd ..
[root@stapp01 www]# ls -rlt
total 4
drwxr-xr-x 2 root root 4096 Mar  4 12:58 html
[root@stapp01 www]# cd /opt/
[root@stapp01 opt]# ls -rlt
total 8
drwxr-xr-x 1 root root 4096 May 23  2020 puppetlabs
lrwxrwxrwx 1 root root   13 Mar  4 12:58 data -> /var/www/html

Step 3) Run puppet agent -tv on app server 2 and validate if the symlink and empty file is created. 

[root@stapp02 ~]# puppet agent -tv
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for stapp02.stratos.xfusioncorp.com
Info: Applying configuration version '1614862834'
Notice: /Stage[main]/Symlink/File[/opt/data/]/ensure: created
Notice: /Stage[main]/Symlink/File[/opt/data/media.txt]/ensure: defined content as '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: Applied catalog in 0.04 seconds
[root@stapp02 ~]# ls /opt/data
media.txt
[root@stapp02 ~]# ls /var/www/html/
media.txt
[root@stapp02 ~]# 

Step 3) Run puppet agent -tv on app server 3 and validate if the symlink and empty file is created. 

[root@stapp03 ~]# puppet agent -tv
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Caching catalog for stapp03.stratos.xfusioncorp.com
Info: Applying configuration version '1614862936'
Notice: /Stage[main]/Symlink/File[/opt/data/]/ensure: created
Notice: /Stage[main]/Symlink/File[/opt/data/media.txt]/ensure: defined content as '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: Applied catalog in 0.06 seconds
[root@stapp03 ~]# ls /opt/data
media.txt
[root@stapp03 ~]# ls /var/www/html/
media.txt
[root@stapp03 ~]# 

No comments: