Integrate your calendar with Ansible to avoid schedule conflicts | Opensource.com

Integrate your calendar with Ansible to avoid schedule conflicts

Make sure your automation workflow's schedule doesn't conflict with something else by integrating a calendar app into Ansible.

Calendar close up snapshot
Image credits : 
by Dafne Cholet. CC BY-SA 2.0.  
x

Subscribe now

Get the highlights in your inbox every week.

Is "anytime" a good time to execute your automation workflow? The answer is probably no, for different reasons.

If you want to avoid simultaneous changes to minimize the impact on critical business processes and reduce the risk of unintended service disruptions, then no one else should be attempting to make changes at the same time your automation is running.

In some scenarios, there could be an ongoing scheduled maintenance window. Or maybe there is a big event coming up, a critical business time, or a holiday—or maybe you prefer not to make changes on a Friday night.

Whatever the reason, you want to signal this information to your automation platform and prevent the execution of periodic or ad-hoc tasks during specific time slots. In change management jargon, I am talking about specifying blackout windows when change activity should not occur.

Calendar integration in Ansible

How can you accomplish this in Ansible? While it has no calendar function per se, Ansible's extensibility will allow it to integrate with any calendar application that has an API.

The goal is this: Before you execute any automation or change activity, you execute a pre-task that checks whether something is already scheduled in the calendar (now or soon enough) and confirms you are not in the middle of a blocked timeslot.

Imagine you have a fictitious module named calendar, and it can connect to a remote calendar, like Google Calendar, to determine if the time you specify has otherwise been marked as busy. You could write a playbook that looks like this:

- name: Check if timeslot is taken
  calendar
:
    time
: "{{ ansible_date_time.iso8601 }}"
  register
: output

Ansible facts will give ansible_date_time, which is passed to the calendar module to verify the time availability so that it can register the response (output) to use in subsequent tasks.

If your calendar looks like this:

Then the output of this task would highlight the fact this timeslot is taken (busy: true):

ok: [localhost] => {
   "output": {
       "busy": true,
       "changed": false,
       "failed": false,
       "msg": "The timeslot 2020-09-02T17:53:43Z is busy: true"
   }
}

Prevent tasks from running

Next, Ansible Conditionals will help prevent the execution of any further tasks. As a simple example, you could use a when statement on the next task to enforce that it runs only when the field busy in the previous output is not true:

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

Conclusion

In a previous article, I said Ansible is a framework to wire things together, interconnecting different building blocks to orchestrate an end-to-end automation workflow.

This article looked at how playbooks can integrate or talk to a calendar application to check availability. However, I am just scratching the surface! For example, your tasks could also block a timeslot in the calendar… the sky is the limit.

In my next article, I will dig into how the calendar module is built and how other programming languages can be used with Ansible. Stay tuned if you are a Go fan like me!


This originally appeared on Medium as Ansible and Google Calendar integration for change management under a CC BY-SA 4.0 license and is republished with permission.

Calendar close up snapshot

Discover how you are spending time by parsing your calendar with Python in Jupyter.
woman on laptop sitting at the window

Concentration offers a quick way to filter out distractions and focus on coding.
Woman sitting in front of her laptop

If Ansible's inclusion as a leader on the Forrester Wave report piqued your interest, here are some ways the automation solution can simplify your life.

Topics

About the author

Nicolas Leiva - Technology professional with 15 years of experience helping customers design, deploy, and operate large-scale networks, with an emphasis on infrastructure automation. Cisco Certified Design Expert (CCDE) and Internetwork Expert (CCIE). Occasional speaker at international conferences and blogger. Enjoys writing open-source software in Go (Golang) and is a Cloud enthusiast.