Science and technology

Integrate your calendar with Ansible to keep away from schedule conflicts

Is “anytime” an excellent time to execute your automation workflow? The reply might be no, for various causes.

If you wish to keep away from simultaneous modifications to reduce the affect on vital enterprise processes and scale back the chance of unintended service disruptions, then nobody else ought to be trying to make modifications on the similar time your automation is working.

In some eventualities, there may very well be an ongoing scheduled upkeep window. Or possibly there’s a massive occasion arising, a vital enterprise time, or a vacation—or possibly you like to not make modifications on a Friday evening.

Whatever the rationale, you wish to sign this info to your automation platform and stop the execution of periodic or ad-hoc duties throughout particular time slots. In change administration jargon, I’m speaking about specifying blackout home windows when change exercise shouldn’t happen.

Calendar integration in Ansible

How are you able to accomplish this in Ansible? While it has no calendar operate per se, Ansible’s extensibility will enable it to combine with any calendar software that has an API.

The purpose is that this: Before you execute any automation or change exercise, you execute a pre-task that checks whether or not one thing is already scheduled within the calendar (now or quickly sufficient) and confirms you aren’t in the midst of a blocked timeslot.

Imagine you have got a fictitious module named calendar, and it could actually hook up with a distant calendar, like Google Calendar, to find out if the time you specify has in any other case been marked as busy. You may write a playbook that appears like this:

- identify: Check if timeslot is taken
  calendar
:
    time
: ""
  register
: output

Ansible details will give ansible_date_time, which is handed to the calendar module to confirm the time availability in order that it could actually register the response (output) to make use of in subsequent duties.

If your calendar appears to be like like this:

Then the output of this job would spotlight the very fact this timeslot is taken (busy: true):

okay: [localhost] =>
   "output":

Prevent duties from working

Next, Ansible Conditionals will assist forestall the execution of any additional duties. As a easy instance, you might use a when assertion on the subsequent job to implement that it runs solely when the sphere busy within the earlier output isn’t true:

duties:
  - shell
: echo "Run this only when not busy!"
    when
: not output.busy

Conclusion

In a previous article, I stated Ansible is a framework to wire issues collectively, interconnecting totally different constructing blocks to orchestrate an end-to-end automation workflow.

This article checked out how playbooks can combine or speak to a calendar software to verify availability. However, I’m simply scratching the floor! For instance, your duties may additionally block a timeslot within the calendar… the sky is the restrict.

In my subsequent article, I’ll dig into how the calendar module is constructed and the way different programming languages can be utilized with Ansible. Stay tuned in case you are a Go fan like me!


This initially appeared on Medium as Ansible and Google Calendar integration for change management beneath a CC BY-SA four.zero license and is republished with permission.

Most Popular

To Top