EX294 Red Hat Certified Engineer RHCE – Exploring Core Components of Ansible Part 6

  • By
  • January 19, 2023
0 Comment

16. Understanding Mixed Variable(Dict+List) with Playbook example

Hello. Welcome to this lecture. In this lecture we will discuss about complex variable consisting of board, dictionary and list variables. Here we have words section defined variable. Name is users. So this user’s variable is list of two items which are further dictionaries. So here this is first list item. And this is second list item. Both items are dictionaries. So here again we can use or we have to use Ginger. Two expressions to reference variable in player book. For example to display users variable. We’ll use this syntax to display first item in the list will use this. We know about this. So this will display this dictionary. Because first item is dictionary item.

Then we can move one step further to display name. In this dictionary we’ll use dot. Then we’ll use name as key to display this name. So in this way we can move one step further to reach the final value we are looking for. Similarly we can display a’s of Lisa by using item number one. And here using age instead of name as key. Now let’s move to the system and understand how this works. We are on ansible control node. And I am logged in as root.

Again I will open same playbook example in a dating mode. And we’ll make corresponding changes. Here variable name is users. And here we need to define two items. Each being dictionary name mark h 35. 2nd item is details about Lisa. Name Lisa is 30. I will delete these lines. And here we need to make corresponding changes. We’ll display complete variable users. So this is all we need to do. I will save and quit.

Now we know we need to execute this playbook. So here we have output. See this output. So we have scar bracket enclosing this variable. So this mean. So this is list variable which contains two dictionary items. Which is indicated by these curly brackets. So now to refer first item in this variable we’ll use zero. I will open this. And here inside scare brackets will mention zero to print first item of this variable which is this dictionary details about Mark. Again I will execute this playbook. Now see here we have dictionary in the output. Because first item is dictionary. Which is indicated by this curly brackets. Now to move further to display for example name of Mark.

We’ll use name key. I will open this. We need to move one step further in the dictionary. We need to print name. We’ll use name key. Here. I’m using Dot notation. We can use bracket notation as well. I will execute playbook. Again we have name in the output. Again I will open this playbook in editing mode. To display a’s of Lisa.

We’ll change this to one which is item one. And here we’ll use age as key. We’ll execute this playbook. We have 30 which is a’s of Lisa. So in this way we can access different values in different variables. You must be able to form different expressions to access variables because this is very important in case you need to execute some playbook based on some variable value. This is all about this lecture?

17. Using YAML file to Define Variables

Hello, welcome to this lecture. In this lecture we’ll discuss how we can use ansible variables defined in YAML file. In previous lecture we discussed example of list variable where each list item was further dictionary variable in the form of key value pairs. Where I would say this was mixed variable variable example here I’m using same example. But instead of defining variable in VAR section, I’m using file defining this variable. Here one file with name VARs underscore file YML is included and these are contents of this file.

This is the same variable we discussed in previous example. The only difference is instead of defining variable directly in the playbook, we are putting this variable in some YAML file. Then we are including that file using VARs underscore files section. So this is good way to define variables when you need to include or define multiple variables in some playbook. So, instead of putting all the variables in the VAR section, you can define variable in some YAML files or in the YAML file. Then using VAR underscore files section, list all the files to be used in the playbook. Now to access or to refer this variable, we can use exactly same expression we used in last example. So there will be no change at all. Now, let’s move to the NSIBL control node and understand how this works. Now we are on an ensable control node and I am logged in as root user.

First of all we’ll create file. To define our variable, we know we need to use variable file name as VARs underscore file dot YML as for example we discussed earlier. Here we’ll define our variable three dashes on the top variable name is users. Here we need to define two list items which are further dictionary variables. We have done three dots indicating end of YAML document. Now we’ll understand how we can use this variable file in playbook.

I will open same playbook in a dating mode. And here instead of VARs we must use VARs underscore files. Then here we’ll list the file defining our variable. File name is VAS underscore file YML. I will remove all this text. Now here I will make corresponding change. However, it will also work fine. First I will display complete variable. I will execute this playbook. So here we have list variable in the output where each list item is for the dictionary. So in this way we can list variables in some YAML file and include YAML file using VARs underscore files section instead of VARs section. In previous lecture we already understood how we can refer or access different list items. And further how we can refer to values associated with different keys. I’m not going to repeat this here. This is all about this task.

18. Setting Variables during Playbook Execution

Hello, welcome to this lecture. In this lecture we’ll learn how we can provide variable or variables during playbook execution. Here we must use VARs underscore prompt section. And here we’ll list our variables or variable as list item. Using name will define variable name. I am using using variable name as VAR. Using prompt, you can type text you want to display to ask for variable during playbook execution, I’m using enter variable private is set to know. This will be more clear when we’ll display this variable using playbook example again, to refer or access this variable, we’ll use same Ginger to expression. Now let’s move to the ensable control node and understand how this works. Now we are on ansible control node and I am logged in as root user.

Again, we’ll open same playbook and we’ll modify this playbook to define our variable. Here we know we must use VARs underscore prompt. Here we’ll use name directive to define name of variable which is VAR as per example. Then here we must use prompt to type text you want to display asking variable. I will type enter variable. I will remove this. And here I will change this to VAR. Because in this case variable name is VAR. Here I’m not using private directive just to show you which is the default behavior when we don’t use this. I will save and quit. I will execute this player book. Here it’s asking to enter variable. I will enter variable as ansible. You must have noticed you did not see this variable. So this is useful when you need to type some password.

So, default behavior is private is set to yes. I will press enter. So here we have variable displayed. Now I will again open this player book.

And I will set private to no. I will save and quit. We’ll execute this player book. This time we can see variable on the screen. So here we have variable displayed. Now we’ll discuss one practical example of creating user using VARs underscore prompt section. So that during playbook execution it will prompt to ask for username. We’ll open same playbook in the dating mode. And here I will change variable name to username. And here I will change it to enter username. Private is set to no. This is okay, because username is not critical to display. Then in the task section I will change this to create user. And here we’ll use user module. We already discussed about user module while discussing ansible ad hoc commands. But here we are using same module in playbook.

Here we’ll use named directive to define username. We must set name directive to this Ginger to expression state must be set to present. Although this is deferred behavior, I will include this. So, this is all we need to do. Now I will save and create will execute this playbook again, here it’s prompting asking username we need to create. I will provide username as test user for example, so user has been created on M host one. So in similar way you can also include password variable but for password we must encrypt password before using it. We’ll discuss more on this later on. Idea here is to make you understand how we can provide ancillary variables during playbook execution. This is all about this lecture? Yeah.

Comments
* The most recent comment are at the top

Interesting posts

Preparing for Juniper Networks JNCIA-Junos Exam: Key Topics and Mock Exam Resources

So, you’ve decided to take the plunge and go for the Juniper Networks JNCIA-Junos certification, huh? Great choice! This certification serves as a robust foundation for anyone aiming to build a career in networking. However, preparing for the exam can be a daunting task. The good news is that this guide covers the key topics… Read More »

Mastering Microsoft Azure Fundamentals AZ-900: Essential Study Materials

Ever wondered how businesses run these days without giant server rooms? That’s the magic of cloud computing, and Microsoft Azure is a leading cloud platform. Thinking about a career in this exciting field? If so, mastering the Microsoft Certified: Azure Fundamentals certification through passing the AZ-900 exam is the perfect starting point for you. This… Read More »

The Impact of Remote Work on IT Certification Exam Processes

With remote work becoming the new norm, it’s not just our daily routines that have changed but also how we tackle IT certification exams. Gone are the days of trekking to testing centers; now, your living room can double as an exam room. This shift has brought about some fascinating changes and challenges. Let’s dive… Read More »

IT Risk Management: CRISC Certification Exam Essentials

Do you ever feel like the IT world is moving at warp speed? New tech seems to pop up every day, leaving you wondering how to keep up and truly stand out in your field. Companies are increasingly concerned about online threats, data leaks, and meeting legal requirements. That’s where the CRISC (Certified in Risk… Read More »

The Ultimate Guide to Mastering Marketing Automation for Email Wizards

Hey there, email aficionados! Welcome to your new favorite read – the one that’s going to turbocharge your email marketing game. You’re about to dive into the captivating world of marketing automation, a place where efficiency meets effectiveness, letting you boost your campaigns without breaking a sweat. Get ready to discover how automation can not… Read More »

Master YouTube Marketing with These 10 Powerful Steps

Welcome to the dynamic world of YouTube marketing! Whether you’re a seasoned pro or just getting started, harnessing the power of YouTube can significantly boost your brand’s visibility and engagement. With over 2 billion monthly active users, YouTube offers a vast audience for your content. But how do you stand out in such a crowded… Read More »

sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |