In the previous video, we have done creating a topology like this. 2
So here we have ubuntu server inside virtualbox. This ubuntu server is connected to internet, 3
connected to router inside gns3, and also connected to host os or our laptop. 4
If you remember, we also able to remote the ubuntu server from our laptop using ssh. Let’s check it, 5
here, we are in the mac os terminal, 6
but this is the ubuntu prompt. This is means that we remote the ubuntu server from our laptop. 7
This ubuntu server will used to do network automation. 8
we will write a network automation script here in the ubuntu server. 9
So we need to make sure that python is installed in the ubuntu server. 10
Let’s type pyt and then tab. Here we can see that we already have python3. 11
Let’s enter here, okay this is python version 3.8.2. Let’s exit. 12
To write the python script, we have multiple way. First, we can use text editor from ubuntu, 13
which is nano. Let’s try, nano and then the file name, let’s say script1.py. 14
Okay we are in the nano text editor, let’s write python script here, let’s say print hello python. 15
Print hello world, and others. 16
Save this, ctrl + x, y, enter. Let’s ls here, here we can see that we have script1.py, 17
let’s run this script. 18
Python script1.py. here we can see that we get hello python and hello world. 19
Another way, we can use sublime text. Sublime text is a desktop text editor, 20
this is means that the sublime text is running on host os, not in the guest os, 21
because the ubuntu server is cli, so we can not install sublime in the ubuntu server. 22
So now the question is, how we can edit the script on our laptop, 23
but the script will also saved on the ubuntu server. 24
This is what we are going to learn in this video, let’s just start. 25
To do that, we need to install additional package in sublime text. 26
Here in the sublime text, type ctrl + shift + p. 27
Or if you use mac, you need to type command + shift + p. But in the windows or linux, 28
we need to type ctrl + shift + p. 29
Here let’s type install and then choose install package control. 30
You can click here or just enter. 31
Wait for a minute. Okay here we get a message that package control was successfully installed. 32
Ctrl + shift + p again, here let’s choose package control: install package. 33
Here we can see some package that we can install in sublime text. 34
Let’s search for sftp. This is the package that we are going to install. Click here. 35
Okay here we get a message that sftp is successfully installed. 36
Now let’s setup the sftp. First, we need to open empty folder in the sublime. 37
File open, and here we can choose the empty folder. 38
Right click here, here we have a choice sftp or ftp. Choose map to remote. 39
Here we need to define the information about ubuntu server. 40
So the host is the ip address of ubuntu server, which is 192.168.56.2. 41
and then the username is ubuntu, and then here for the password, let’s remove the slash. 42
This slash means comment. And then here let’s type the password of ubuntu server. 43
I will change the password of ubuntu server first. 44
Let’s back to sublime text. And type the password here. 45
And then remote path, this is the path in the ubuntu server. 46
so later, the local path will be synchronize to the path in the ubuntu server. 47
Let’s say I will synchronize to the home directory in the ubuntu server. 48
Let’s type pwd here. The path is /home/ubuntu. 49
So here let’s put /home/ubuntu. 50
You can see the configuration here and change some configuration that you want to change. 51
In this case, I want to change this configuration, 52
upload on save. This is means that the sublime will upload the file to the ubuntu server 53
when we save the file. The default is false, let’s change this become true. 54
We have done here, save this. Right click here in the folder, sftp, 55
synchronize remote to local. This is means we synchronize from the ubuntu server to our laptop. 56
Here we can see that we connect to 192.168.56.2 as ubuntu, wait for a minute. 57
Here we can see some file from ubuntu server that will synchronized to our laptop. 58
Oh I am sorry, this is cancel when I click here. Right click again, sftp, 59
and then synchronize remote to local 60
Here we can see some file that will downloaded to our laptop. 61
But here we can see some file that we don’t need in our laptop, .ssh/config, .ssh/known_hosts and others. 62
So in this case, I will choose no. 63
Here in the sftp configuration, we have ignore regex. We can put file or directory 64
that we don’t want to synchronize here. In this case, we want to ignore .ssh. save. 65
Let’s try to synchronize again. Here we can see that .ssh is not downloaded anymore. Yes here. 66
Okay we have done, here we can see that now we have script1.py, 67
this is the script that we write in the ubuntu server before. 68
Let’s try to edit this, 69
Print hello java. Save this, here we can just cancel it. 70
Back to the terminal, 71
ls, here we can see that we only have script1.py, may be some of you have a question, 72
why when we synchronize in the sublime, we get a lot of file? 73
This is because, file that started by dot is hidden file, to see hidden file in ubuntu, we can use ls -a. 74
Okay here we can see many file that started by dot, this is means hidden file. 75
Okay now let’s run script1.py, 76
here we can see that now we have hello java. 77
Remember that we add hello java from our laptop in the sublime text. 78
So now when we edit from sublime text, the file will be saved automatically on ubuntu server. 79
Let’s try to create new file from sublime text. Let’s say script2.py, 80
write a python script here, let’s say print hello java and then print hello python. Save. 81
Now let’s go to ubuntu, ls, here we can see that we have script2.py, 82
let’s run this script, python script2.py. 83
Okay here we get hello java and hello python. 84
So now we can edit the script in the sublime text, 85
and the script will be automatically saved in the ubuntu server. 86
I think enough for this video. In the next video, we are going to learn 87
how to install package in python. 88
Thank you for watching and see you on the next video.