Puppet Create Symlinks

Ticker

6/recent/ticker-posts

Puppet Create Symlinks

Question: There are directory structures in the Stratos Datacenter that need to be changed, including directories that need to be linked to the default Apache document root. We need to accomplish this task using only Puppet as per the instructions given below:

Create a puppet programming file demo.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/dba 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/dba directory on all puppet agent nodes i.e on all App Servers.

Note: Please perform this task using demo.pp only, do not create any separate inventory file.


Please Note :-  Perform the below commands based on your question  server,  user name & other details might differ . So please read task carefully before executing. All the Best 👍


Solution:  

1Go through the folder mentioned in task and create puppet files

root@jump_host /# cd /etc/puppetlabs/code/environments/production/manifests/

root@jump_host /etc/puppetlabs/code/environments/production/manifests# ll

total 0

root@jump_host /etc/puppetlabs/code/environments/production/manifests#

root@jump_host /etc/puppetlabs/code/environments/production/manifests# vi demo.pp

root@jump_host /etc/puppetlabs/code/environments/production/manifests# cat demo.pp

class symlink {

  # First create a symlink to /var/www/html

  file { '/opt/dba':

    ensure => 'link',

    target => '/var/www/html',

  }

   # Now create media.txt under /opt/dba

  file { '/opt/dba/media.txt':

    ensure => 'present',

  }

}

node 'stapp01.stratos.xfusioncorp.com', 'stapp02.stratos.xfusioncorp.com', 'stapp03.stratos.xfusioncorp.com' {

  include symlink

}

root@jump_host /etc/puppetlabs/code/environments/production/manifests#

2. Validate the puppet files by below command.refer Video below for clarity )

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

root@jump_host /etc/puppetlabs/code/environments/production/manifests#

3. Login on all  App server  (stapp01stapp02, stapp03 ) & switch to root  user 

root@jump_host /# ssh tony@stapp01

The authenticity of host 'stapp01 (172.16.238.10)' can't be established.

ECDSA key fingerprint is SHA256:w9cDRojDoclOxdu1W23Ns2HPyANPrDzhk9VfqtTDoJQ.

ECDSA key fingerprint is MD5:a8:3b:55:35:c2:5c:56:76:c8:d0:78:13:7a:4d:8b:e1.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'stapp01,172.16.238.10' (ECDSA) to the list of known hosts.

tony@stapp01's password:

[tony@stapp01 ~]$ sudo su -

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

[sudo] password for tony:

[root@stapp01 ~]#

4. Run Puppet agent to pull the configuration from puppet server 

[root@stapp01 ~]# puppet agent -tv

Info: Using configured environment 'production'

Info: Retrieving pluginfacts

Info: Retrieving plugin

Info: Retrieving locales

Info: Loading facts

Info: Caching catalog for stapp01.stratos.xfusioncorp.com

Info: Applying configuration version '1624860136'

Notice: /Stage[main]/Symlink/File/[/opt/dba]/ensure: created

Notice: /Stage[main]/Symlink/File/[/opt/dba/media.txt]/ensure: created

Notice: Applied catalog in 0.02 seconds

[root@stapp01 ~]#


5. Validate the task by listing the destination folder

[root@stapp01 ~]# ll /var/www/html/

total 0

-rw-r--r-- 1 root root 0 May 17 05:53 media.txt

[root@stapp01 ~]#

[root@stapp01 ~]#  ll /opt/dba

lrwxrwxrwx 1 root root 13 May 17 05:53 /opt/dba ->  /var/www/html

[root@stapp01 ~]#


Please Note :- I have showed only for stapp01
You have to do this in all app server stapp01,stapp02, stapp03. 

6.  Click on Finish & Confirm to complete the task successful

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , 

please go through and share your comments. Like and share the knowledge



Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user