1 00:00:06,660 --> 00:00:09,340 - In this lesson, we are going to talk about variables. 2 00:00:09,340 --> 00:00:10,890 And before we are diving into 3 00:00:10,890 --> 00:00:14,060 the details of vault of variables and facts, 4 00:00:14,060 --> 00:00:16,030 I want to give you an overview 5 00:00:16,030 --> 00:00:18,910 of how variables are used by talking about 6 00:00:18,910 --> 00:00:22,500 separating code from site-specific configuration. 7 00:00:22,500 --> 00:00:25,430 That's one of the DevOps best practices. 8 00:00:25,430 --> 00:00:28,340 Ansible itself is all about configuration as code. 9 00:00:28,340 --> 00:00:29,310 Let's face it. 10 00:00:29,310 --> 00:00:30,730 You define your playbooks, 11 00:00:30,730 --> 00:00:33,076 in your playbooks, in YAML file you define the configuration 12 00:00:33,076 --> 00:00:36,160 that you want to enroll on the managed assets 13 00:00:36,160 --> 00:00:38,030 in your environment. 14 00:00:38,030 --> 00:00:40,210 And if you are developing flexible code, 15 00:00:40,210 --> 00:00:43,590 you should separate site-specific information from the code 16 00:00:43,590 --> 00:00:45,200 which will be static. 17 00:00:45,200 --> 00:00:47,420 We've already seen that a couple of times. 18 00:00:47,420 --> 00:00:50,050 If in your playbook, you are too specific 19 00:00:50,050 --> 00:00:52,470 then it's not going to work out well. 20 00:00:52,470 --> 00:00:56,180 So you need to try to maintain a certain obstruction level 21 00:00:56,180 --> 00:00:59,773 in your playbook and to keep out very specific information. 22 00:01:00,880 --> 00:01:02,560 If you develop dynamic code 23 00:01:02,560 --> 00:01:05,430 where your static code is combined with variables 24 00:01:05,430 --> 00:01:08,070 that allows you to use your code on any site 25 00:01:08,070 --> 00:01:12,230 reduce some minor modifications in the variables themselves. 26 00:01:12,230 --> 00:01:14,900 So to provide the site-specific information, 27 00:01:14,900 --> 00:01:16,840 variables I use. 28 00:01:16,840 --> 00:01:19,660 And apart from variables, Ansible provides facts. 29 00:01:19,660 --> 00:01:20,720 Well, I'm not even sure 30 00:01:20,720 --> 00:01:24,320 if I should put it that way, because effect is a variable. 31 00:01:24,320 --> 00:01:26,030 The only difference is that variables 32 00:01:26,030 --> 00:01:29,040 in general are defined by the system administrator 33 00:01:29,040 --> 00:01:33,170 and Ansible effects are discovered on the managed machines. 34 00:01:33,170 --> 00:01:35,230 So effects are system properties that are 35 00:01:35,230 --> 00:01:39,080 dynamically discovered, and you can use them as variables. 36 00:01:39,080 --> 00:01:41,540 And separating site-specific information 37 00:01:41,540 --> 00:01:46,220 from static code is also referred to as decoupling. 38 00:01:46,220 --> 00:01:47,360 So what does that mean? 39 00:01:47,360 --> 00:01:51,130 That means that you should try to develop your playbooks 40 00:01:51,130 --> 00:01:53,850 in such a way that they can be used throughout. 41 00:01:53,850 --> 00:01:55,760 If you want to use them somewhere else, 42 00:01:55,760 --> 00:01:58,780 the only thing you need to change is the variables. 43 00:01:58,780 --> 00:02:00,070 In the next couple of videos, 44 00:02:00,070 --> 00:02:02,070 we are going to discover how this works.