1,760
edits
Changes
→Part 2: Set up more administrative tasks
== Part 2: Set up more administrative tasks==
:Let's pretend that we needed to deploy a web server need collect the disk usage on several machinesso that we can plan for storage maintenance. We'll set up a simple example of such a deployment here.
=== Getting the disk usage on remote worker ===
</source>
:You'll find that yum prompts you to answer questions, which you don't want to do in an automated environment. And also yum prints too much output, which also isn't helpful in an automated environment. We'll fix it by adding two switches to yum: "-y" and "-d1":
:Notice also that all of the four commands can be run as many times as you want, the result will be the same. This is not always so easy.
=== Update all the rpm packages on remote worker ===
:Let's pretend that we need to update software packages installed on several machines due to security patches. Let's name the task as 'performSoftwareUpdate()':<source lang="python">
# to perform software update on remote worker
def performSoftwareUpdate():
status = run('yum update -y')
print(status)
</source>
: Do a syntax check with the "fab -l" command.
: When you try to run it the same way as before, you encounter some issue as shown below:<source lang="bash">
[rchan@centos7 lab8]$ fab --fabfile=fabfile.py -H 192.168.122.169 performSoftwareUpdate
[192.168.122.169] Executing task 'performSoftwareUpdate'
[192.168.122.169] run: yum update -y
[192.168.122.169] out: Loaded plugins: fastestmirror, langpacks
[192.168.122.169] out: You need to be root to perform this command.
[192.168.122.169] out:
Fatal error:<source lang="html"><h1>My fancy web server</h1></source>run() received nonzero return code 1 while executing!
Requested:And since we're pretending that it's a large website with many files and directories, we'll compress it into an archive named '''webcontents.tar.bz2''' using a tar command. You've done this since OPS235.yum update -yExecuted: /bin/bash -l -c "yum update -y"
</source>
: As you already know, you need superuser privilege in order to perform software update on a Linux system. There are two ways to do it on Fabric. The first one is simple. Edit you fabfile.py and change the env.user line as shown below:<source lang="python">
== Part 2: Set up the firewall ==