Can I use conditional execution in Fabric?

Is it possible to ask the fabric to perform actions conditionally? This should be pretty trivial because it is "just Python", but I'm not 100% sure how to run commands and capture their return code or output.

As an example, how would I have behavior that depends on the value of the environment variable in the host?

+4
source share
1 answer

It is pretty simple:

@hosts('host.example.com') def task(): if run('echo $SOME_VAR') == 'some value': run('some_other_command.sh') 
+6
source

Source: https://habr.com/ru/post/1385801/


All Articles