Puppet String Manipulation

Ticker

6/recent/ticker-posts

Puppet String Manipulation

Question:  There is some data on App Server 2 in Stratos DC. The Nautilus development team shared some requirement with the DevOps team to alter some of the data as per recent changes. The DevOps team is working to prepare a Puppet programming file to accomplish this. Below you can find more details about the task.

Create a Puppet programming file demo.pp under /etc/puppetlabs/code/environments/production/manifests directory on Puppet master node i.e Jump Server and by using puppet file_line resource perform the following tasks.

We have a file /opt/sysops/demo.txt on App Server 2. Use the Puppet programming file mentioned above to replace line Welcome to Nautilus Industries! to Welcome to xFusionCorp Industries!, no other data should be altered in this file.

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 data_replacer {

  file_line { 'line_replace':

    path => '/opt/sysops/demo.txt',

    match => 'Welcome to Nautilus Industries!',

    line  => 'Welcome to xFusionCorp Industries!',

  }

}

node 'stapp02.stratos.xfusioncorp.com' {

  include data_replacer

}

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 App server  stapp02 & switch to root  user 

root@jump_host /# ssh steve@stapp02

The authenticity of host 'stapp02 (172.16.238.11)' 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 'stapp02,172.16.238.11' (ECDSA) to the list of known hosts.

steve@stapp02's password:

[steve@stapp02 ~]$ 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 steve:

[root@stapp02 ~]#

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

[root@stapp02 ~]# puppet agent -tv

Info: Using configured environment 'production'

Info: Retrieving pluginfacts

Info: Retrieving plugin

Info: Retrieving locales

Info: Loading facts

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

Info: Applying configuration version '1624860136'

Notice: /Stage[main]/Data_replacer/File_line[Line_replace]/esure:  created

Notice: Applied catalog in 0.05 seconds

[root@stapp02 ~]#

5. Validate the task by running cat /opt/sysops/demo.txt

[root@stapp02 ~]# cat /opt/sysops/demo.txt

This is Nautilus sample file, created using Puppet !

Welcome to xFusionCorp Industries!

Please do not modify this file manually!

[root@stapp02 ~]#


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