First commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import json
|
||||
from playbook import StepLog, CustomStep, Play, Status
|
||||
from dataclasses import asdict
|
||||
|
||||
def pre(ctx) -> StepLog:
|
||||
ctx["a"] = 5
|
||||
|
||||
return StepLog(
|
||||
"pre something",
|
||||
Status.GOOD,
|
||||
0,
|
||||
msg="set 5",
|
||||
)
|
||||
|
||||
def play(ctx):
|
||||
ctx["a"] = ctx["a"] + 10
|
||||
|
||||
return StepLog(
|
||||
"play something",
|
||||
Status.BAD,
|
||||
0,
|
||||
msg="added 10",
|
||||
)
|
||||
|
||||
def post(ctx):
|
||||
ctx["a"] = ctx["a"] / 2
|
||||
|
||||
return StepLog(
|
||||
"post something",
|
||||
Status.GOOD,
|
||||
0,
|
||||
msg=f"halved {ctx["a"]}",
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
newPlay: Play = Play("backup dirs")
|
||||
|
||||
newPlay.add_step(
|
||||
"backup dirs",
|
||||
CustomStep(
|
||||
"custom step",
|
||||
pre, play, post,
|
||||
)
|
||||
)
|
||||
|
||||
print(newPlay.view_playbook())
|
||||
|
||||
print(json.dumps(asdict(newPlay.play()), indent=2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user