Changes

Jump to: navigation, search

OPS435 Python3 Lab 8

6,278 bytes added, 17:10, 3 July 2020
Investigation 2 - Running the fab command in ad-hoc mode
fab [options] -- [shell commands]
</source>
: When running the fab command in ad-hoc mode, it is very similar to running the SSH with commands attached at the end. == Part 1: running non-privileged shell commands on remote machines ==: Try the following ad-hoc fab commands and record their results for later use:<source lang='bash'>
[raymond.chan@mtrx-node05pd lab8]$ fab --host=myvmlab.senecacollege.ca --port=7200 --user=student -- 'date;hostname;id'
[myvmlab.senecacollege.ca] Executing task '<remainder>'
</source>
: Note that there is no password prompting if you complete part 3 successfully, otherwise, the SSH server daemon on your VM will prompt you for a password. The output from the fab's ad-hoc mode is not much different from the SSH command with shell command attached at the end, however, please note that the additional information on the output from the fab command can be very useful for record keeping purpose - what has been done and whether the commands had been carried out successfully or not.
 
== Part 2: running privileged commands on remote machines ==
: We say that running an ad-hoc fab command is very similar to the SSH command with shell commands attached at the end. Let's try both with privileged commands, like the "yum" command.
 
=== Run the "yum" command on remote machine with SSH ===
: By default, your VM doesn't have the "tree" rpm package installed. You can verify this with the following SSH command:<source lang='bash'>
[raymond.chan@mtrx-node05pd lab8]$ ssh -p 7200 student@myvmlab.senecacollege.ca "yum list tree"
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.mirror.colo-serv.net
* extras: centos.mirror.colo-serv.net
* updates: centos.mirror.ca.planethoster.net
Available Packages
tree.x86_64 1.6.0-10.el7 base
[raymond.chan@mtrx-node05pd lab8]$
</source>
: Please note that the tree package is "Available", but not yet installed.
: Let't try to install the "tree" package with the shell command "yum install tree -y":<source lang='bash'>
[raymond.chan@mtrx-node05pd lab8]$ ssh -p student@myvmlab.senecacollege.ca "yum install tree -y"
Loaded plugins: fastestmirror
You need to be root to perform this command.
</source>
: Using the "yum" command to query rpm package doesn't need special privilege, however, it does when you try to install or remove rpm packages.
: Your "student" account on your VM was configured to allow you to run the "sudo" command to perform software management using the "yum" command. Let's login to your VM and try the following "sudo" command to install and then remove the "tree" rpm package:<source lang='bash'>
[raymond.chan@mtrx-node05pd lab8]$ ssh -p 7200 student@myvmlab.senecacollege.ca
Last login: Fri Jul 3 16:51:07 2020 from mtrx-node05pd.dcm.senecacollege.ca
[student@centos7 ~]$ sudo yum install tree -y
[sudo] password for student:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: less.cogeco.net
* extras: centos.mirror.colo-serv.net
* updates: mirror.calgah.com
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Installing:
tree x86_64 1.6.0-10.el7 base 46 k
 
Transaction Summary
========================================================================================================================
Install 1 Package
 
Total download size: 46 k
Installed size: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1
 
Installed:
tree.x86_64 0:1.6.0-10.el7
 
Complete!
[student@centos7 ~]$
</source>
: Please note that when you run the "sudo" command the first time, it asks you for the user's password (i.e. user student's password). Let's now remote the "tree" package:<source lang='bash'>
[student@centos7 ~]$ yum remove tree -y
Loaded plugins: fastestmirror
You need to be root to perform this command.
[student@centos7 ~]$ sudo yum remove tree -y
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be erased
--> Finished Dependency Resolution
 
Dependencies Resolved
 
========================================================================================================================
Package Arch Version Repository Size
========================================================================================================================
Removing:
tree x86_64 1.6.0-10.el7 @base 87 k
 
Transaction Summary
========================================================================================================================
Remove 1 Package
 
Installed size: 87 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1
 
Removed:
tree.x86_64 0:1.6.0-10.el7
 
Complete!
[student@centos7 ~]$
</source>
: The above tests confirm that the student user is allowed to run the yum command to install and remove rpm package. Now let's logout from the VM and go back to matrix. On matrix, try to run the sudo command using SSH:<source lang='bash'>
[student@centos7 ~]$ exit
logout
Connection to myvmlab.senecacollege.ca closed.
[raymond.chan@mtrx-node05pd lab8]$ ssh -p 7211 student@myvmlab.senecacollege.ca "sudo yum install tree -y"
sudo: no tty present and no askpass program specified
[raymond.chan@mtrx-node05pd lab8]$
</source>
: The above error indicated that you need a tty for the SSH session to prompt you for the sudo password. Please look up the ssh man page to find out the option which turn on a tty for the SSH session.
: Let's try the corresponding ad-hoc fab command:<source lang='bash'>
fab --host=myvmlab.senecacollege.ca --port=7200 --user=student -- 'sudo yum install tree -y'
</source>
: Type in student's password when prompted for "sudo password".
: Try remove the "tree" rpm package with the appropriate ad-hoc fab command.
= INVESTIGATION 3: Running fab in script mode =
1,760
edits

Navigation menu