One way of doing it is 'with quiet():'
with quiet():
result = local("something")
if result.failed:
....
else:
....
Question
I'd like to do something as simple as check if a string can be found in a file, and if not then do something. Fabric exits with an error. What work around is there?
result = local("grep %s /tmp/file" % env.hosts[0])
if result.failed:
print "shit failed"
else:
print "was already added, noop!"
Outputs
# fab -H 1.2.3.5
[localhost] local: grep 1.2.3.5 /etc/bitrate/puppetmaster/firewall
Fatal error: local() encountered an error (return code 1) while executing 'grep 1.2.3.5 /etc/bitrate/puppetmaster/firewall'
Aborting.
La solution
One way of doing it is 'with quiet():'
with quiet():
result = local("something")
if result.failed:
....
else:
....