1
00:00:00,000 --> 00:00:12,866
Hi, Let us understand how to modify scope using 'with' . I can create a block of restricted scope using with

2
00:00:12,866 --> 00:00:16,766
keyword. I can have a with and then a pipeline where

3
00:00:16,766 --> 00:00:20,899
It's going to evaluate a condition or it's going to read a collection of values.

4
00:00:20,900 --> 00:00:27,900
And once the condition is evaluated, it's going to execute the collection of statements within the block.

5
00:00:27,900 --> 00:00:34,633
And the value that got evaluated using the pipeline will be available or can be used only within that

6
00:00:34,633 --> 00:00:38,433
specific block, within the restricted scope.

7
00:00:38,433 --> 00:00:42,499
Let us understand, using a small demo. Let me get into the chart that we had created.

8
00:00:42,500 --> 00:00:45,333
Let me add some sample values.

9
00:00:45,333 --> 00:00:47,566
I'm going to edit the values file. Here

10
00:00:47,566 --> 00:00:55,099
I'm going to add a key called tags and it's going to have a collection of key value pair like machine as key

11
00:00:55,100 --> 00:00:56,900
and frontdrive as value

12
00:00:56,900 --> 00:01:01,466
Like that I have some key and value pair within the key tags.

13
00:01:01,466 --> 00:01:03,366
So this is something like a map.

14
00:01:03,366 --> 00:01:06,999
Or we can visualize this as a collection as well.

15
00:01:07,000 --> 00:01:10,733
Now I'm going to change the template. So within the template

16
00:01:10,733 --> 00:01:21,166
I'm going to add the with condition and I'm going to read the values.tags, observe the space whitespace.

17
00:01:21,166 --> 00:01:26,699
So I do have two white spaces and the condition is getting started over here.

18
00:01:26,700 --> 00:01:34,100
And the key value pair, I am adding it in the same indent where I am doing the evaluation with

19
00:01:34,100 --> 00:01:39,000
I am adding the keyword then I'm getting the values.tags

20
00:01:39,000 --> 00:01:44,433
So all the values within the tags will be available only within this specific scope and within

21
00:01:44,433 --> 00:01:48,366
this scope, the global within this specific scope

22
00:01:48,366 --> 00:01:51,966
The builtin objects will also be not accessible.

23
00:01:51,966 --> 00:01:53,899
We will do that as a separate demo.

24
00:01:53,900 --> 00:01:58,900
Now I'm going to use this specific values.tag as a with and directly

25
00:01:58,900 --> 00:02:06,300
I can access.machine because the parent scope of this particular block is tags. So within the tags

26
00:02:06,300 --> 00:02:15,033
I can access the machine, rack, dry and Vcard. Let me go ahead and execute the dry run.

27
00:02:15,033 --> 00:02:18,833
And the entire content of this particular YAML file as well as the commands

28
00:02:18,833 --> 00:02:24,833
It will be added along with the resources so directly you can download and start using them.

29
00:02:24,833 --> 00:02:28,499
Now, let me go ahead and do a dry run.

30
00:02:28,500 --> 00:02:33,933
Now, let me go ahead and do a dry run.

31
00:02:33,933 --> 00:02:42,966
So the condition got evaluated and it read the Values SSD, frontdrive, 4c and 8g and it got printed here.

32
00:02:42,966 --> 00:02:48,899
Now let's go ahead and try another scenario of how the indent can be used.

33
00:02:48,900 --> 00:02:53,500
Getting into the template here the same values from the tags

34
00:02:53,500 --> 00:03:00,300
I'm going to read and add it as a part of the labels.

35
00:03:00,300 --> 00:03:05,300
This is another good example to understand how the white space should be used, so within labels, I

36
00:03:05,300 --> 00:03:09,000
am going to have a set of labels that is first, second and third.

37
00:03:09,000 --> 00:03:14,266
The values will be picked because I am using with within this particular block.

38
00:03:14,266 --> 00:03:20,499
So it's going to read all the values from the tags and all the references within this particular block

39
00:03:20,500 --> 00:03:23,933
will be to that particular tags scope only.

40
00:03:23,933 --> 00:03:27,066
So within the tags, it's going to read machines, rack and dry.

41
00:03:27,066 --> 00:03:34,199
And with the same indent, it's going to print the values, let me go ahead and do a dry run.

42
00:03:34,200 --> 00:03:37,366
The dry run will be very useful for debugging as well.

43
00:03:37,366 --> 00:03:44,799
So within labels, I do have three labels with the key and value and it got added. So the whitespace

44
00:03:44,800 --> 00:03:46,900
Indent is very, very important.

45
00:03:46,900 --> 00:03:51,500
Now, let's go ahead and add something which is not there within the scope.

46
00:03:51,500 --> 00:03:58,633
So within this specific block, I'm going to access the builtin object release.name

47
00:03:58,633 --> 00:04:03,566
So within the tags I will not have anything with release or name.

48
00:04:03,566 --> 00:04:06,966
So there should not be any value getting printed for this.

49
00:04:06,966 --> 00:04:15,399
Let me go ahead and do a dry run. Its not getting any value.

50
00:04:15,400 --> 00:04:22,633
So the yaml it turned out to be a not valid template, and there are some options to solve this

51
00:04:22,633 --> 00:04:28,266
particular problem and definitely there will be a need to access the builtin objects within the

52
00:04:28,266 --> 00:04:31,766
blocks and we can solve it using variables.

53
00:04:31,766 --> 00:04:34,799
We will be discussing about variables in future lecture.

54
00:04:34,800 --> 00:04:39,033
And I can go ahead and add this particular release name.

55
00:04:39,033 --> 00:04:43,233
outside the restricted block and that should work.

56
00:04:43,233 --> 00:04:49,099
If I add this particular release name outside this restricted block

57
00:04:49,100 --> 00:04:56,300
this should work. Let me go ahead and do a dry run.

58
00:04:56,300 --> 00:04:59,400
And yes, it's able to read the release name.

59
00:04:59,400 --> 00:05:07,200
So basically within the restricted block, we cannot use the values from other scope or even the builtin objects.

60
00:05:07,200 --> 00:05:11,900
We cannot access and that should be accessed using the variables.

61
00:05:11,900 --> 00:05:15,133
And this restricted block will be very useful whenever I wanted to

62
00:05:15,133 --> 00:05:17,533
iterate over a given set of values

63
00:05:17,533 --> 00:05:23,666
or given set of arrays it will be very useful so that I can work only on that restricted set of values.

