A place to cache linked articles (think custom and personal wayback machine)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hace 4 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. title: Do-nothing scripting: the key to gradual automation
  2. url: https://blog.danslimmon.com/2019/07/15/do-nothing-scripting-the-key-to-gradual-automation/
  3. hash_url: 00a288de97e8a854d5fdfe03ba2bcf72
  4. <p>Every ops team has some manual procedures that they haven’t gotten around to automating yet. <a href="https://landing.google.com/sre/sre-book/chapters/eliminating-toil/">Toil</a> can never be totally eliminated.</p>
  5. <p>Very often, the biggest toil center for a team at a growing company will be its procedure for modifying infrastructure or its procedure for provisioning user accounts. Partial instructions for the latter might look like this:</p>
  6. <ol><li>Create an SSH key pair for the user.</li><li>Commit the public key to Git and push to master.</li><li>Wait for the build job to finish.</li><li>Find the user’s email address in the employee directory.</li><li>Send the user their private key via 1Password.</li></ol>
  7. <p>This is a relatively short example. Sometimes there are 20 steps in the process. Sometimes there are branches and special cases to keep track of as you go. Over time, these procedures can become unmanageably large and complex.</p>
  8. <p>Procedures like this are frustrating because they’re focus-intensive yet require very little thought. They demand our full attention, but our attention isn’t rewarded with interesting problems or satisfying solutions – just another checkbox checked. I have a word for a procedure like this: a <strong>slog</strong>.</p>
  9. <p>We know that this procedure is ripe for automation. We can easily see how to automate any given step. And we know that a computer could carry out the instructions with far greater speed and accuracy than we can, and with less tendency toward <a href="https://risk-engineering.org/concept/Rasmussen-practical-drift">practical drift</a>.</p>
  10. <p>However, automating slogs sometimes feels like an all-or-nothing proposition. Sure, we could write a script to handle step 2, or step 5. But that wouldn’t <em>really</em> make the procedure any less cumbersome. It would lead to a proliferation of single-purpose scripts with different conventions and expectations, and you’d still have to follow a documented multi-step procedure for using those scripts.</p>
  11. <p>This perception of futility is the problem we really need to solve in order to escape from these manual slogs. I’ve found an approach that works pretty reliably: <strong>do-nothing scripting</strong>.</p>
  12. <h2>Do-nothing scripting</h2>
  13. <p>Almost any slog can be turned into a <strong>do-nothing script</strong>. A do-nothing script is a script that encodes the instructions of a slog, encapsulating each step in a function. For the example procedure above, we could write the following do-nothing script:</p>
  14. <pre class="brush: python; title: ; notranslate" title="">
  15. import sys
  16. def wait_for_enter():
  17. raw_input("Press Enter to continue: ")
  18. class CreateSSHKeypairStep(object):
  19. def run(self, context):
  20. print("Run:")
  21. print(" ssh-keygen -t rsa -f ~/{0}".format(context["username"]))
  22. wait_for_enter()
  23. class GitCommitStep(object):
  24. def run(self, context):
  25. print("Copy ~/new_key.pub into the `user_keys` Git repository, then run:")
  26. print(" git commit {0}".format(context["username"]))
  27. print(" git push")
  28. wait_for_enter()
  29. class WaitForBuildStep(object):
  30. build_url = "http://example.com/builds/user_keys"
  31. def run(self, context):
  32. print("Wait for the build job at {0} to finish".format(self.build_url))
  33. wait_for_enter()
  34. class RetrieveUserEmailStep(object):
  35. dir_url = "http://example.com/directory"
  36. def run(self, context):
  37. print("Go to {0}".format(self.dir_url))
  38. print("Find the email address for user `{0}`".format(context["username"]))
  39. context["email"] = raw_input("Paste the email address and press enter: ")
  40. class SendPrivateKeyStep(object):
  41. def run(self, context):
  42. print("Go to 1Password")
  43. print("Paste the contents of ~/new_key into a new document")
  44. print("Share the document with {0}".format(context["email"]))
  45. wait_for_enter()
  46. if __name__ == "__main__":
  47. context = {"username": sys.argv[1]}
  48. procedure = [
  49. CreateSSHKeypairStep(),
  50. GitCommitStep(),
  51. WaitForBuildStep(),
  52. RetrieveUserEmailStep(),
  53. SendPrivateKeyStep(),
  54. ]
  55. for step in procedure:
  56. step.run(context)
  57. print("Done.")
  58. </pre>
  59. <p>This script doesn’t actually <em>do</em> any of the steps of the procedure. That’s why it’s called a do-nothing script. It feeds the user a step at a time and waits for them to complete each step manually.</p>
  60. <p>At first glance, it might not be obvious that this script provides value. Maybe it looks like all we’ve done is make the instructions harder to read. But the value of a do-nothing script is immense:</p>
  61. <ul><li>It’s now much less likely that you’ll lose your place and skip a step. This makes it easier to maintain focus and power through the slog.</li><li>Each step of the procedure is now encapsulated in a function, which makes it possible to replace the text in any given step with code that performs the action automatically.</li><li>Over time, you’ll develop a library of useful steps, which will make future automation tasks more efficient.</li></ul>
  62. <p>A do-nothing script doesn’t save your team any manual effort. It lowers the activation energy for automating tasks, which allows the team to eliminate toil over time.</p>