Trending February 2024 # How Php Ucwords() Works With Examples # Suggested March 2024 # Top 11 Popular

You are reading the article How Php Ucwords() Works With Examples updated in February 2024 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested March 2024 How Php Ucwords() Works With Examples

Introduction to PHP ucwords()

Ucwords() in PHP is a built-in function. It is helpful to convert the first and foremost character of a string into uppercase. The ucwords() only supports PHP 4 & above versions. ucwords() function takes a string as an input value and it outputs the string by changing the first letter/character of the string into uppercase. Other than this every other character remains the same as the previous time. The ucwords() function in PHP returns converted to string by changing the first letter of all words to uppercase.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax Ucwords($string, $separator)

The ucwords() syntax accepts just two parameters.

1. $string( string mandatory ): Between the parenthesis of ucwords() function, string input is required. It is a must and mandatory to this function declaration in order to specify the string which is to be converted.

2. $separator ( Optional Parameter ): Separator is the optional parameter of ucwords() function. It contains words separator characters. The separator used in the input string for the words. The listed characters which are listed below are by default:

t for tab


r for Carriage return

n for newline

v for vertical tab

f for form feed

$Separator parameter added in 5.5.16, 5.4.32 versions of PHP.

How PHP ucwords() works?

PHP ucwords works when the text/words contain mixed types of letters/characters inside words. Only the first character of the word/ first characters of all the words which are in the sentence will be converted to capital letters. It works using a string value that contains word/words and it also uses one separator/delimiter value but it is optional. No issue with the separator variable.

Examples of PHP ucwords()

Given below are the examples

Example #1

How the basic program works by using ucwords() PHP function.


<?php $input_string = "hey buddy, pavan sake is coming just wait."; echo "Before:". $input_string; $result_string = ucwords($input_string); echo "After: ".$result_string;


Example #2


<?php $result_string1 = ucwords($input_string); echo $result_string2;


Example #3

This example here is to use ucwords() function on arrays which has a list of names/strings by removing delimeters/parameters “–“ and “”.


<?php function ucname($string1) { $string1 =ucwords(strtolower($string1)); foreach (array('-', ''') as $parameters1) { if (strpos($string1, $parameters1)!==false) { $string1 =implode($parameters1, array_map('ucfirst', explode($parameters1, $string1))); } } return $string1; } <?php $names1 =array( 'SAKE-PAVAN KUMAR', 'ANIL O'KUMAR', 'MARUTHI PRASAD', 'surendra la gandham', 'rAjAsEkHaR KAtUbaDi' ); /* Sake-Pavan Kumar Anil O'Kumar Maruthi Prasad Surendra La Gandham Rajasekhar Kattubadi */


Example #4

This is one of the sample programs of ucwords function.

This program has features like:

Multibyte/bytes Compatability

It handles delimiters even if there are multiple


<?php function ucwords_specific1 ($string1, $delimiters1 = '', $encoding1 = NULL) { if ($encoding1 === NULL) { $encoding1 = mb_internal_encoding();} if (is_string($delimiters1)) { $delimiters1 =  str_split( str_replace(' ', '', $delimiters1)); } $delimiters_pattern11 = array(); $delimiters_replace11 = array(); $delimiters_pattern21 = array(); $delimiters_replace21 = array(); foreach ($delimiters1 as $delimiter1) { $uniqid1 = uniqid(); $delimiters_pattern11[]   = '/'. preg_quote($delimiter1) .'/'; $delimiters_replace11[]   = $delimiter1.$uniqid1.' '; $delimiters_pattern21[]   = '/'. preg_quote($delimiter1.$uniqid1.' ') .'/'; $delimiters_replace21[]   = $delimiter1; } $return_string1 = $string1; $return_string1 = preg_replace($delimiters_pattern11, $delimiters_replace11, $return_string1); $words1 = explode(' ', $return_string1); { $words1[$index1] = mb_strtoupper(mb_substr($word1, 0, 1, $encoding1), $encoding1).mb_substr($word1, 1, mb_strlen($word1, $encoding1), $encoding1); } $return_string1 = implode(' ', $words1); $return_string1 = preg_replace($delimiters_pattern21, $delimiters_replace21, $return_string1); return $return_string1; } <?php mb_internal_encoding('UTF-8'); $string1 = "PAVAN KUMAR-SAKE d'alltechscience şŠ-òÀ-éÌ hello - web"; echo ucwords_specific1( mb_strtolower($string1, 'UTF-8'), "-'");


The main parameters which are involved in the above program are $string1, $delimeter1, $delimiters, encoding. Delimeter/Delimeters are the parameters that are an option but needed In the development. The string is the parameter that is to be converted. The encoding parameter is to know the character encoding. Internal characters encoding value/values will be used if the parameter don’t omits.

Example #5


<?php $title1 = 'PAVAN "THE KING" SAKE - (I WANT TO BE YOUR) SERVANT'; echo ucwords(strtolower($title1)); <?php function my_ucwords($string1) { $noletters1='"([/'; for($i=0; $i<strlen($noletters1); $i++) $string1 = str_replace($noletters1[$i], $noletters1[$i].' ', $string1); $string1=ucwords($string1); for($i=0; $i<strlen($noletters1); $i++) $string1 = str_replace($noletters1[$i].' ', $noletters1[$i], $string1); return $string1; } $title1 = 'PAVAN "THE KING" SAKE - (I WANT TO BE YOUR) SERVANT'; echo my_ucwords(strtolower($title1));


Example #6

This is the example of the code below which will convert all your words into small letters except the first letter. They will be a capital letter. Here ucfirst() function is used. It is also a part of ucwords() function.


<?php $text1 = "What Buddy ? No 'parameters',shit! "happening" chúng tôi solves many problems now???"; for ($i = 0; $i < count($data1[0]); $i++) { $data1[0][$i] = ucfirst($data1[0][$i]); } $text1 = implode("", $data1[0]); print $text1;


The above program’s output contains the same text which is under $text1 variable but just the first characters of the words which are listed in the variable will be changed to the capital letters remaining ones will remain as small letters.

Recommended Articles

This has been a guide to PHP ucwords(). Here we discuss syntax, parameters, and examples of PHP ucwords(). you may also have a look at the following articles to learn more –

You're reading How Php Ucwords() Works With Examples

How Does Mongodb Unique Works With Examples

Introduction to MongoDB Unique

MongoDB’s Unique Constraint makes certain that the fields indexed in it, do not store duplicate values for the same field, i.e., making sure the uniqueness of fields. By default, MongoDB enforces this unique constraint on the “_id” field, while inserting new data. One of the major responsibilities is to ensure no duplicate data has been stored in a single key. We also have restrictions here, like MongoDB will be unable to establish a unique index on any specific field, in case if the collection somehow has already stored any data that would breach the feature of unique constraint for the index.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others


Now that we have understood what Unique Constraint in MongoDB, let us learn the standard syntax to write this Unique method.

db.collection_name.createIndex( {field_name : 1} , {unqiue : true} )

How UNIQUE Constraint works in MongoDB?

The Unique Index allows the insertion and storing of the values in a document into a collection IF there is no other document in the same collection with the same index key and value. The unique constraint can be implemented on compound indexes. This helps MongoDB to implement uniqueness when combining the index key values.  Unique Constraint over separate multiple documents is possible in MongoDB, and it is an essential function in avoiding storing of same values for the indexed key in a different document.

Unique Constraint in MongoDB will allow only a single document with the same value for the indexed key. If we attempt to insert the same value for a single indexed key, it will result in an error.

Query #1


This returns every document in the collection.

Query #2

db.code.insert( { name:”kumar”, city:“Pune”, code:19 } )

This is an attempt to insert a record with the same code.




Explanation: Here, we have implemented the unique index for “code” key, and so when we try to store a document with existing code, it results in “duplicate key error”.

Unique Constraint for Null Value

When we store any document, we store values for the respective keys, and it is stored as per indexing. But in case, if we attempt to store a document that has no specific value or data for a key, for any uncertain key, the document will be stored, and the empty value will be stored as a null value in that document.  In MongoDB, only on the document is allowed to be stored with a single index field missing.

Examples to Implement UNIQUE Constraint in MongoDB

Implementing Unique Contraint on separate documents to not store the same value for the indexes key, in two different documents.

Example #1

We will attempt to insert and store documents with duplicate values. We have a collection named educba, which we will check with find method: db.educba.find()




As you can see in the above image, we have a collection named educba, and the document has one default unique “_id” and two more keys. We will now implement the unique constraint on the “Name”, which will make it unique, duplicate insertion proof.


db.educba.createIndex( { “Name” : 1 } , { unique : true } )



db.educba.insert({ Name : "Sulaksh" ,  City : "Pune" })


First Query:db.educba.insert({ Name : "Sulaksh" ,  City : "Pune" })

The above query will be successfully inserted.  Then we attempted to insert the same query, i.e. same document with the same values, but it resulted in an error that states, “terms”: “E11000 duplicate key error collection: test.educba index: Name_1 dup key: { : ”Sulaksh” }””. This makes our unique constraint applied over the Name field successfully.

Example #2


db.educba.createIndex( {email : 1},{unique : true} )


We will not attempt to insert a document with a different name but an email id that already exists in another document. Expectations are that the insertion operation will not work and through us an error of duplicate value. We have another document with a slightly different name: Sanket1, for the test purpose, and now we will attempt to update the document with an email: [email protected]


db.educba.update( { “Name” : ”Sanket1” } , { $set : {email : “[email protected]” }})

Above query will aim to search a record with Name: Sanket1 and will update the record with adding an email id to the document, here $set will add a field for the document.


As you can see in the above screenshot, when we attempted to update a record with the different Name field, the email was the same as one existing document. It threw us a write error, which means an error occurred while writing the document. The error states “duplicate key error collection: test. educba index: email_1 dup key”. The error points to the issue and makes things clear for us to understand.  Like in our case, the email with the value of “[email protected]” is duplicated, already stored, so it will not store again due to unique indexing on the email field. In case you want to know, I’ve used the update with $get to add another field for existing records.

Use Case for this example: Is the New User Registration where we have to ensure that a single mail id is not used to create multiple accounts.


Implementing Unique Constraint will restrict the database from storing duplicate values for the same indexed key to wrap it up. This feature helps in storing documents with uniqueness. We learned and understood the syntax followed by the working of it. Then we implemented the unique constraint with example and understood the same along with screenshots, respectively.

Recommended Articles

This is a guide to MongoDB Unique. Here we discuss an introduction, how does Unique works and examples for better understanding. You can also go through our other related articles to learn more –

Learn How Untar Works In Ansible With Examples

Introduction to Ansible untar

Ansible untar module also known as unarchive for Unix OS or win_zip for the windows operating system is used to extract or unpack the archive files or folders on the remote destination by copying the archive file first by default on the remote server and also supports many parameters to deal with the unarchive or win_zip functionality like the owner, dest, exclude and more.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others


For the non-windows target unarchive or ansible.builtin.unarchive command uses the below syntax. We have shown the basics parameters


copy: No / Yes (Default)

The default Option is Yes and it copies the files from the local controller to the remote host if specified yes or nothing specified. For working with the remote source need to specify the remote_src and this copy parameter is not helpful there.

src (required):

Source path of the file. If remote_src is ‘yes’ then the source path would be on the remote location otherwise the source path is on the local controller node.

dest (required):

Remote server absolute path where the archive is going to extract.

remote_src: no (Default) / yes

If set ‘yes’ specifies that the source archive path is on the remote computer. For the ‘no’ value the path is on the local controller node.


name of the user that should own the files/directory after unpack and same replicates (added) to the chown.


Name of the group that should own the files/directory and same replicates (added) to the chown.


List of files or directories that need to be excluded from the unpacking.


List of files or directories that need to be included in the unpacking process.

keep_newer: no (default) / yes

If set yes, it replaces the existing files that are newer than the files inside the archive.


Permissions that the files or directories should have after unpacked (like 644, 777, etc).

For the windows target src, dest, creates parameters remain the same as unarchive module and the additional parameters are as below.


delete_archive: no (default) / yes

Removes the zip file after unzipping.


If the Zip file is password encrypted then this parameter is useful and it requires the PSCX module to be installed.

recurse: no (default) / yes

recursively expands the zip file within the src directory.

Setting value ‘yes’ requires the PSCX module to be installed.

Please note: the win_unzip module doesn’t use the remote_src parameter.

How untar works in Ansible?

Ansible unarchive module for non-windows target comes with the ansible-base and so it is included in the Ansible installations. For the windows target, we need to use the win_unzip module. If the module is not available then you can download it from the galaxy.

ansible-galaxy collection install

Below is the simple playbook for windows untar (unzip).

dest: c:temp7zipInstaller


The above playbook will unzip the file from the source location to the destination remote servers. If the destination path doesn’t exist it creates the destination path.

You must have noticed here, although the source path is remote, we don’t need to use remote_src because the win_unzip module doesn’t support it and when we use the remote source path for the non-target windows server we must specify the remote_src. For example,

remote_src: yes


Here are the following examples mention below

Example #1 – unarchive module task for UNIX os.

dest: /tmp/phyes

In this playbook, it will retrieve the chúng tôi file to the destination remote host /tmp/phyes. Before running this task unlike the win_unzip module, you need to make sure that the destination path exists otherwise it will throw an error.


Example #2 – Exclude files from the archive.

To exclude the certain file from the unpacking we can use h


exclude: ’Test1 document.txt’

If there are multiple files to exclude then you can provide the list as below.

- ’’

Example #3 – Include files from the archive


include: ’Test1 document.txt’

The above playbook will include only the test1 text file and to include the multiple documents, use the below command.

- ’’

Example #4 – using multiple parameters together.


owner: ansibleadmin

In the above playbook, it will include only 2 files, keep_newer parameter will not replace the existing files that are newer than files from the archive, remote_src indicates the remote source and it will set the owner permission on the files and it will keep the file permission 0644.


Untar or unarchive or unzip modules are very useful when we write the playbook. It makes it easier to extract the files or folders on the destination server without using any third-party software and in addition, it uses various parameters like we don’t need to copy the file before extracting, adding permissions after extract, etc.

Recommended Articles

This is a guide to  Ansible untar. Here we discuss How untar works in Ansible and Examples along with the codes and outputs. You may also look at the following articles to learn more –

Penetration Pricing Strategy: Meaning, How It Works, Examples

What is Penetration Pricing Strategy?

Penetration pricing strategy is a marketing strategy wherein a new product or service is introduced at a relatively low price to attract new customers. 

For example, Reliance JIO entered the Indian telecom industry with a penetration price approach. With its financial capabilities, Reliance JIO was able to acquire the essential facilities and offer the services for three months without charge. However, after three months, the prices steadily rose.

Start Your Free Investment Banking Course

Download Corporate Valuation, Investment Banking, Accounting, CFA Calculator & others

Low prices attract consumers in any market where competitors have already captured the share. It focuses on making the consumers aware of the product. A price penetration strategy aims to persuade customers to try a new product and gain market share, hoping to retain new clients after prices return to their previous rates.

Key Highlights

This strategy is implemented to penetrate the market at a low price.

The lower price of the product introduces the product in the market where existing competitors have already captured their share.

It attracts a wide number of customers due to low prices.

One of the challenges is retaining the customer that the low price has attracted.

The risk is that consumers might switch once the price increases.

How Does a Penetration Pricing Strategy Work?

It prioritizes market share over profitability for a specific time period. The objective is to quickly create demand, expand a consumer base, and maximize brand loyalty.

The corporation first lowers the price to encourage people to try a new product or service. The corporation sets an affordable price for its value while remaining less expensive than the standard alternatives.

Competitors must match the deal or immediately implement alternative techniques since the first price undercuts it. Competitors’ clients may move to the less expensive offer, and new customers may sign up.

After a time of expansion, the company usually raises prices to boost profits and account for the increasing value of its product.

A company typically employs penetration pricing when it anticipates high demand for a new good or service. They hope that the sales volume will offset the lower-than-usual cost.

Real-World Examples Example #1: Netflix

Netflix entered the market by offering free access to a larger movie library in exchange for waiting one or two days for a DVD to arrive. There was no due date, and four movies could be rented once for $15.95 a month.

Even though Netflix subscription costs frequently increased, people were happy to pay them in exchange for a steady stream of high-quality media content.

Netflix currently holds 51% of streaming subscriptions in the United States, making it the market leader.

Netflix reduced prices on all plans in India by 18–60% in 2023 in order to expand its customer base and what is widely regarded as a premium service in the country.

Example #2: Starbucks

Starbucks, a high-end coffee chain, frequently offers discounted versions of innovative and seasonal beverages and coffees to attract customers to try them.

After customers become accustomed to these items on the menu and demonstrate a favorable response, Starbucks withdraws the penetration pricing offers and resumes selling them at regular, non-discounted prices.

Example #3: Costco and Kroger

Costco and Kroger, two major grocery store chains, use market penetration pricing to sell organic foods. They offer lower prices on organic food and have successfully used penetration pricing to grow their wallet share.

These companies can afford to charge less because they buy large quantities at a bulk discount. They can maintain their profit margins while beating their competitors’ prices due to lower expenses.

Penetration Pricing vs. Skimming Price Strategy

To launch any product into the market, penetration pricing and skimming price are the most common strategies. Companies implement them for a shorter duration.

Skimming Price Strategy

Companies implement a skimming price strategy on an already acquired customer base or an untouched territory. This strategy works well in industries that are dependent upon innovation. Apple, for example, continues to use the skimming pricing method.

Apple’s approach before launching each generation of new products is to arouse customer expectations and curiosity.

Despite its relatively high price, Apple’s sales have not decreased. On the contrary, due to a large number of loyal customers, it has outstanding market sales. Furthermore, Apple lowers the prices of its older products as it introduces newer ones.

Penetration Pricing Strategy

Companies use this pricing strategy when launching a product in a highly competitive market. The idea is to attract customers by offering lower prices, such as Reliance JIO.

Reliance JIO entered the Indian telecommunications market using a penetration pricing strategy.

Reliance JIO had the resources to acquire the necessary infrastructure and provide free services for three months.


Acquiring more customers: A good high-quality product launched at comparatively low prices attracts a large number of customers. Upfront resources: The resources required to produce many goods will also be substantial.

Lower production cost: By increasing sales, there would be an increase in production. Consequently, the cost of production will become lower. Poor brand image: A lowered-price product is not necessarily always seen as good. A product that has a low price could be perceived as cheap or of low quality.

Less competition: By lowering the prices, the product will become affordable to the existing customers, which will lower the competition. Low customer loyalty: When the prices increase, customers might return to competitors’ brands, as they get the same product at a lower price.

Final Thoughts

Penetration pricing is a good strategy to introduce the product in highly competitive markets. The lower product cost would help the brand reach out to a huge number of customers that might become loyal to the brand afterward.

This strategy works best in industries that have huge demand. It gives a competitive edge, lowers production costs, and helps acquire a substantial customer base.

Frequently Asked Questions(FAQs) Q1. What are penetration prices and skimming prices?

Answer: In order to maximize immediate earnings, price skimming raises prices to attract clients most interested in the good or service. In contrast,  penetration pricing uses lower prices to create a consumer base for new products or services.

Q2. Could penetration pricing work if the quality of the product is lower than the existing products? Q3. Should we opt for a penetration pricing strategy to penetrate any market?

Answer: Like every strategy, it depends on the situation and the resources available to answer whether a brand should opt for such a strategy. Industries use it where there is huge demand, and every participant offers almost similar products.

Q4. What factors should be considered while opting for a penetration pricing strategy?

Answer: There are several factors, namely, the industry size, the nature of the product, the price offered by competitors, available resources, and most importantly, the motive.

Q5. How are the prices raised after the implementation of the penetration pricing strategy?

Answer: Companies should raise high costs after some time. Prices increase gradually. For example, streaming service offering companies may offer the services at $40 per year instead of their actual price of $100. Now, the company would wait to raise the price to $100. Instead, the company might raise the price to $60 from $40, then to $75, then finally, to $100.

Recommended Articles

This article explains everything about Penetration Pricing Strategy. To know more, visit the following articles:

How To Use Isblank With Examples

ISBLANK Function

Checks if a specified cell is blank or not

Written by

CFI Team

Published July 2, 2023

Updated July 7, 2023

What is Excel ISBLANK Function?

The ISBLANK Function[1] is an Excel Information function that returns true if the argument cell has no information in it. ISBLANK checks a specified cell and tells us if it is blank or not. If it is blank, it will return TRUE; else, it will return FALSE. The function was introduced in MS Excel 2007.

In financial analysis, we deal with data all the time. The ISBLANK function is useful in checking if a cell is blank or not. For example, if A5 contains a formula that returns an empty string “” as a result, the function will return FALSE. Thus, it helps in removing both regular and non-breaking space characters.

However, if a cell contains good data, as well as non-breaking spaces, it is possible to remove the non-breaking spaces from the data.




Value (required argument) is the value that we wish to test. (This function takes in a cell)

How to use the Excel ISBLANK Function

As a worksheet function, ISBLANK can be entered as part of a formula in a cell of a worksheet. To understand the uses of this function, let us consider a few examples:

Highlight Missing Values – Example

Suppose we are given the following data:

Suppose we wish to highlight cells that are empty. We can use the ISBLANK coupled with conditional formatting. For example, suppose we want to highlight the blank cells in the range A2:F9, we select the range and use a conditional formatting rule with the following formula: =ISBLANK(A2:F9).

How to do conditional formatting?

The input formula is shown below:

We will get the results below.

Conditional formatting didn’t highlight cell E5. After checking, there is a formula inserted into the cell.

The Excel ISBLANK function will return TRUE when a cell is actually empty. If a cell is an empty string (“”), ISBLANK will return FALSE, as it is not technically blank,  and it won’t be highlighted as shown above.

Extracting the first NON-Blank value in an array

Suppose we wish to get the first non-blank value (text or number) in a one-row range. We can use an array formula based on the INDEX, MATCH, and ISBLANK functions.

We are given the data below:

Here, we want to get the first non-blank cell, but we don’t have a direct way to do that in Excel. We could use VLOOKUP with a wildcard *, but that will only work for text, not numbers.

Hence, we need to build the functionality by nesting formulas. One way to do it is to use an array function that “tests” cells and returns an array of TRUE/FALSE values that we can then match with MATCH. Now MATCH looks for FALSE inside the array and returns the position of the first match found, which, in this case, is 2. Now the INDEX function takes over and gets the value at position 2 in the array, which, in this case, is the value PEACHES.

As this is an array formula, we need to enter it with CTRL+SHIFT+ENTER.

We get the results below:

Additional Resources

Thanks for reading CFI’s guide to important Excel functions! By taking the time to learn and master these functions, you’ll significantly speed up your financial modeling and valuation analysis. To learn more, check out these additional CFI resources:

Guide To How Ansible Debug Work With Examples

Introduction to Ansible Debug

In Ansible, when we create and run playbooks, it’s very common that we run into an error due to some issues with our playbook. This can be a syntax error, a logical error or some mandatory parameter is missing. So, this is very important that we should always write our playbook in such have a way that it always prints enough information, be it successful or failure. In Ansible, a module named debug is the requirement when you need to debug and when you need more information in playbook execution output.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

In this article we will try to learn some concepts and see Ansible debug examples. This is a default module that comes with Ansible package. This module prints statements and variable’s values when executing playbooks. This can be very helpful in cases, where you can skip some erratic tasks in the playbook and don’t want to stop it altogether. Using debug in all the erratic tasks, will provide you enough information about the data execution in those tasks and all variables used in such tasks. This will help in troubleshooting and is very useful if you use it with registered variables. We will explore such cases in the example section.

How do Ansible Debug works?

In Ansible debug module comes with some parameters and these parameters accept some options. This is given below:

msg: – This parameter accepts strings as inputs. This is used to print a customized message. If no message is given, then a generic message like “Hello World!” is

var: – This accepts strings as input and this is the variable that has been set either by Ansible facts or by the playbook. Also, the values written here will be having implicit double interpolation, as this option runs in the jinja2 context. So, you don’t need to use jinja2 delimiter unless you want to print double interpolation as well. You can use double interpolation when you print a variable in a

verbosity: – This has default as 0. This parameter is used to control when debug is in a run. For example if value 3 is given then debug will only run if -v or above is given while running the playbook.

Examples to Implement Ansible Debug

Now we will take some examples, but before going there, we first understand our lab used for testing purposes. Here we have an Ansible control server named ansible-controller and two remotes hosts named host- one and host-two. We will create playbooks and run Ansible commands on the ansible-controller node and manage the users on remote hosts.

Examples #1

To print a default message on the output of running a playbook via ansible-playbook, we can create a simple playbook like below:


name: Here we use Ansible debug debug:


ansible-playbook debug_dafault_msg.yml

Example #2

To print the value of a variable that was defined in the same playbook. we can create a simple playbook like below:


var: fruit


ansible-playbook debug_print_var.yml

Example #3

To print an Ansible fact of remote hosts, we can create a simple playbook like



ansible-playbook debug_ansible_fact.yml

Example #4

To print a customized message on the screen, Write a playbook like below:


msg: “This is machine is {{ ansible_hostname }} with IP {{ ansible_default_ipv4.address }}”


ansible-playbook debug_with_customized_msg.yml

Example #5

You can register the output of a task in a variable and as we know the values of these variables will be stored in JSON format. So, you can call that variable later in the same playbook. To test this or to test which value will be used when we call registered variables. We can use debug like below, creating a playbook.



ansible-playbook debug_register_values.yml

Example #6

Controlling Verbosity is done by giving values against parameter verbosity and then mentioning the same or more number of –v while running the playbook. Like the playbook in previous. Where we didn’t define any verbosity, then by default it ran with 0 verbosity level. But if define the verbosity level like below:


var: free_mem.stdout_lines verbosity: 1


ansible-playbook debug_register_values.yml -v


Ansible debug module is a very helpful tool for playbook developers and for administrators who work on need to update a playbook frequently on per need basis. Also, while working in a team where others also have the same stakes as you, using the debug module to add more information is always beneficial and can avoid confusion and dependencies.

Recommended Articles

This is a guide to Ansible Debug. Here we discuss an introduction to Ansible Debug, how does it work with examples. You can also go through our other related articles to learn more –

Update the detailed information about How Php Ucwords() Works With Examples on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!