Skip to main content

runbook.py (v0.2)

pip3 install runbook

Inspired by this blog post by Dan Slimmon.

Define your own run-book in a class extending from Runbook. Every method that doesn't begin with an underscore is read in as a step to be completed, in order. The step name will be built from the method name, and the description is taken either from the method's own docstring or from any data returned from invoking the method.

from runbook import Runbook


class CustomRunbook(Runbook):
   
    def first_step(self):
        """
        Do ABC now.
        """
    
    def second_step():
        """
        Do EFG then wait 1 hour.
        """

    def third_step():
        task = "reboot"
        return f"perform a {task}"
    
    @staticmethod
    def last_step():
        """Everything ok?"""

Every Runbook object comes with a default main method that you can use to execute the script.

if __name__ == '__main__':
    CustomRunbook.main()

The run-book object can also be instantiated and run directly.

book = CustomRunbook(file_path="path/to/file")
book.run()

You should avoid using the step names run and main, which are already defined. If you need to override these methods to define custom behavior then that is fine.

As steps are completed, the results are written out to a log file. You can set a custom log file path by passing an argument to main, as in:

python3 my_runbook.py output.log

When reusing the same log file, already completed steps will be skipped. Any new steps found in the Runbook and not already in the log will be processed as normal, with results appended to the end of the file.

License

Licensed under the Apache Software License 2.0 (ASL 2.0).

Release files for runbook 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for runbook 0.2
File Size Uploaded
runbook-0.2.tar.gz 7.5 kB Details

Release files / runbook-0.2.tar.gz

Download URL runbook-0.2.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9fe4f79b5f4df371d8e033b326c73a430d7164f1203190b38e341398fd7d222a
BLAKE2b-256 checksum
How to use checksums
b1d283561aa90f11bed58a8f1efcf8fed8db0c76157d5495dbd9241d81dbfcdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page