문제

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.
도움이 되었습니까?

해결책

One way of doing it is 'with quiet():'

with quiet():
    result = local("something")
        if result.failed:
            ....
        else:
            ....
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top