Skip to content

Simple app to verify whether a time slot is taken/busy in Google Calendar from Ansible.

License

Notifications You must be signed in to change notification settings

nleiva/check-calendar

Repository files navigation

Check Calendar

Ansible Lint

Simple app to verify whether a timeslot is taken/busy or not from Ansible.

Requirements

Go

If you want to compile the examples, you need Go installed. Otherwise you can use the binaries included for convenience in here.

Google Calendar API

You need to turn on the Google Calendar API and download your OAuth 2.0 client credentials (json file) from API Credentials as in the image below.



Name this file as desktop.json, as we reference it in the code.

b, err := ioutil.ReadFile("desktop.json")
if err != nil {
	return false, fmt.Errorf("Unable to read client secret file: %v", err)
}

The file token.json will be automatically generated once an API Token has been granted. Store this file securely as it will have a refresh token that never expires.

Compiling

To compile your own binaries for multiple target Operating Systems (GOOS), run make compile. The binaries in this repo were compiled in an amd64 platform (GOARCH).

Testing

Manually

Execute make test-manual. You need an arguments file named args.json with something like:

{
    "Name": "Test",
    "Time":  "2020-09-01T19:50:00Z"
}

Note: Z is the zone designator for the zero UTC offset.

From Ansible

Execute: make test-ansible.

...
- name: Test the module (from role)
  calendar_linux:
    name: Testing the Calendar module
    time: "{{ ansible_date_time.iso8601 }}"
  register: output
...

If you are running this during a big event or scheduled maintenance window, the module will return true so you can act accordingly. See this calendar example:



The output would look as follows. Notice "busy": true or "msg": "The timeslot 2020-09-02T17:53:43Z is busy: true".

$ make test-ansible
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Test Calendar module] **********************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [localhost]

TASK [Print the time (ISO 8601) - Module input] **************************************************************************************************************
ok: [localhost] => {
   "ansible_date_time.iso8601": "2020-09-02T17:53:43Z"
}

TASK [go-role : Test the module (from role)] *****************************************************************************************************************
included: /home/centos/check-calendar/roles/go-role/tasks/Linux.yml for localhost

TASK [go-role : Test the module (from role) on Linux [Linux]] ************************************************************************************************
ok: [localhost]

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

PLAY RECAP ***************************************************************************************************************************************************
localhost                  : ok=5    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Art work

Repo image from Maria Letta's Free Gophers Pack

About

Simple app to verify whether a time slot is taken/busy in Google Calendar from Ansible.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published