Changes

Jump to: navigation, search

OPS435 Python3 Lab 8

1,575 bytes added, 14:26, 4 July 2020
PART 1: Simplest example
:You should get used to the above messages from the '''fab''' command. It's a lot of output but it's important to understand where every part is coming from, so you are able to debug problems when they happen.
 
===Creating privileged tasks: install and remove rpm package on remote machines===
: Add the following two new functions to the end of the fabric script "fabfile.py" in your lab8 directory:<source lang='bash'>
 
def installPackage(pkg='dummy'):
cmd = 'yum install ' + pkg + ' -y'
status = sudo(cmd)
print(status)
 
def removePackage(pkg):
if pkg == '':
cmd = 'yum remove dummy -y'
else:
cmd = 'yum remove ' + pkg + ' -y'
status = sudo(cmd)
print(status)
</source>
: Note that both functions take one function argument in different ways. However, if no function argument is passed when calling the function, both will default to a string value of "dummy". Both functions call the sudo() from the fabric.api to execute the command contained in the "cmd" object on the remote machine via sudo.
: To check for any syntax error in your updated fabric script, run the following command in the same directory as the fabfile.py:<source lang='bash'>
fab -l
</source>
: You should get a list of tasks defined similar to the following:<source lang='bash'>
[raymond.chan@mtrx-node05pd lab8]$ fab -l
Available commands:
 
getHostname
installPackage
removePackage
[raymond.chan@mtrx-node05pd lab8]$
</source>
: Run the following two fab commands, note the results and compare their difference:<source lang='bash'>
fab installPackage
 
fab installPackage:tree
<source lang='bash'>
: Run the following two fab commands, note the results and compare their difference:
<source lang='bash'>
fab removePackage
 
fab removePackage:tree
</source>
== Part 2: Set up more administrative tasks==
1,760
edits

Navigation menu