Task Automation
Start course

In this lesson, we will introduce common maintenance tasks and explain how to fully automate the work using different tools.

We will discuss how to integrate Azure with Chef and Puppet. We will explain the how to automate Chef to ensure that configuration changes are automatically propagated quickly.

You will learn how to automate resource deletion and re-creation using Chef and Puppet or using a runbook with a Powershell Workflow. If you are unfamiliar with runbooks and Powershell Workflows, we will go into some detail about them and how they can help automate many simple maintenance tasks.


Azure is very flexible when it comes to arbitrary task automation. In this short lesson we will introduce a few common maintenance tasks and explain how we can fully automate the work using different tools.


As we have seen in earlier lessons, Azure integrates well with management tools such as Chef and Puppet. If, for example, you are already very comfortable with Chef, then it trivial to automate any task defined in your Chef code on subsets of your servers. There is an easy to use cron Chef cookbook that lets you define cronjobs. One common use-case is to automate the chef-client run itself to run every few minutes. This ensures that configuration changes are automatically propagated quickly.


Another common need is automated resource deletion and re-creation. For example a business may want to save money by not running Azure VM’s during non-work hours. Automating this safely requires ensuring you have a reliable way of preserving the environment’s state and then recreating and deleting resources easily. This is do-able using Chef and Puppet if you have your infrastructure well-defined in your config management code. A perhaps easier approach, however, is to use a runbook with a Powershell Workflow.


As mentioned in the previous lesson, runbooks are just collections of Powershell scripts. An Azure Powershell Workflow uses runbooks to execute a series of tasks. Workflows add a number of useful features to your Runbooks. For one, they can be scheduled, and they can include automated failure recovery and retry logic. Workflows can help automate many simple maintenance tasks. For example, you can create workflows that save your environment state every day at 8 pm and then delete unneeded resources. Then you can have another workflow that executes a runbook to recreate everything the next day at 8 am. This would cut your Azure hourly costs in half.


You might need several different scripts to do all of the work of snapshotting your environment, deleting everything safely, and then recreating everything in the right order with proper tests to ensure environment health. You could combine the scripts into multiple runbooks and multiple workflows.


Powershell workflows are great for people comfortable writing scripts. For people that prefer to focus on GUI tools, Azure has its Logic Apps system. Azure Logic Apps let you automate and schedule workflows. Logic Apps are similar to Powershell scripts in that they can include conditional statements, switches, loops, and branches. All of this is definable in the GUI, so if you have ever done any coding using a GUI you will have a sense of what to expect.  You can define a logic app in the Azure portal. You will have to define a resource group to let the logic app know what Azure components it will access, and then you define a schedule trigger, which lets you set the exact time interval for when to execute the app.


So that’s basically all you need to know about task automation in Azure. You have your third party services like Chef and Puppet. These integrate well so if you’re familiar with them you can continue to lean on them with Azure. If you prefer writing scripts perhaps because you like checking them into version control and being more transparent, Powershell works great with Azure runbooks and workflows. If you are not as confident about writing scripts, you’ve got Azure Logic Apps, and that will let you automate pretty much anything involving Azure resources.


So keep those core three approaches in mind and congrats on making it through this final section of the course. We will finish up with a final course summary in the next lesson. See you there.

About the Author

Jonathan Bethune is a senior technical consultant working with several companies including TopTal, BCG, and Instaclustr. He is an experienced devops specialist, data engineer, and software developer. Jonathan has spent years mastering the art of system automation with a variety of different cloud providers and tools. Before he became an engineer, Jonathan was a musician and teacher in New York City. Jonathan is based in Tokyo where he continues to work in technology and write for various publications in his free time.