from pyinfra import host from pyinfra.operations import server, files if host.fact.file(host.data.undocker_cache+'/photoprism.tar'): server.shell( name='Remove photoprism Docker image', chdir=host.data.undocker_cache, commands=['rm photoprism.tar'], ) if host.fact.directory(host.data.undocker_dst): server.shell( name='Remove undocker destination', commands=['rm -rf {}'.format(host.data.undocker_dst)], )