As this year draws to an end i.e. today is the 31st of December as I’m writing this article. We are sure that your email and phone inboxes would be filled with wishes from your loved ones and friends. We wanted to take this opportunity to share our best wishes to you in an interesting Ansible way.

In this article, we will share an Ansible playbook which prints the line “HAPPY NEW YEAR TO ALL” in a very colorful manner. We’ll show you how to execute the playbook properly but we will not do a deep dive into the plugins that are responsible for generating the output.

To get started we need the GitHub repository ansible-cowmas. You can download the repository to your local system from the URL or you can clone it directly if you are using git on your local system.

I’ve downloaded the repository from the URL and copied it to my local system.

[root@linuxnix seasons_greetings]# ls

Let’s extract this zip file now.

[root@linuxnix seasons_greetings]# unzip
creating: ansible-cowmas-master/
inflating: ansible-cowmas-master/.gitignore
inflating: ansible-cowmas-master/LICENSE
inflating: ansible-cowmas-master/
inflating: ansible-cowmas-master/ansible.cfg
creating: ansible-cowmas-master/callback_plugins/
inflating: ansible-cowmas-master/callback_plugins/
inflating: ansible-cowmas-master/hello_world.yml
[root@linuxnix seasons_greetings]# ls
[root@linuxnix seasons_greetings]#

Now let’s take a peek at the contents of the directory.

[root@linuxnix seasons_greetings]# cd ansible-cowmas-master/
[root@linuxnix ansible-cowmas-master]# ls
ansible.cfg callback_plugins hello_world.yml LICENSE
[root@linuxnix ansible-cowmas-master]#


The callback_plugins directory contains a python script which is responsible for generating all the wonderful colorful display of text that our playbook execution will print.

[root@linuxnix ansible-cowmas-master]# cd callback_plugins/
[root@linuxnix callback_plugins]# ls

The ansible.cfg file contains the below content:

[root@linuxnix ansible-cowmas-master]# cat ansible.cfg
callback_whitelist = cowmas
stdout_callback = cowmas

The two statements are related to callback plugins. Callback plugins enable adding new behaviors to Ansible when responding to events.
By default, callback plugins control most of the output you see when running the command line programs, but can also be used to add as an additional output, integrate with other tools and marshall the events to a storage backend. So, within our ansible.cfg file, we are allowing the output from the execution of the script to print to the screen during playbook execution.

The hello_world.yml file is our playbook and it simply uses the debug module to print the message Hello World!.

Given below is the content of the playbook.

[root@linuxnix ansible-cowmas-master]# cat hello_world.yml
- name: Hello World Sample
hosts: all
failed: false
changed: false
- name: Hello Message
msg: "Hello World!"
failed_when: failed
changed_when: changed
[root@linuxnix ansible-cowmas-master]#


To execute the playbook we need to type the following command:

ansible-playbook -i sahil, -c local hello_world.yml

I’ve specified my own name as the hostname. you may specify a name of your choice as long as you conform to the syntax of the command.  The hostname doesn’t really matter much because I’ve used the -c local option to ensure that the playbook executes on the localhost only.

When you execute the playbook, you’ll see the colorful output as shown in the screenshot below:


The script that was in the callback_plugins directory was originally supposed to say “HAPPY AUTOMATING TO ALL” but I changed it to “HAPPY NEW YEAR TO ALL”.

You may update it accordingly to your liking by editing the python script using an editor of your choice. I used vim here. The text to be printed is on line number 95 in the script.

[root@linuxnix callback_plugins]# grep -n HAPPY
95: print colorize("HAPPY NEW YEAR TO ALL!\n")
[root@linuxnix callback_plugins]#



In this article, we showed you to download the season’s greetings playbook from GitHub on to your local system and execute it to see a nice greeting message.

We encourage you to download and share this greeting with your cherished ones and from us at the Linux Juggernaut, we wish you a very Happy New Year.

The following two tabs change content below.

Sahil Suri

He started his career in IT in 2011 as a system administrator. He has since worked with HP-UX, Solaris and Linux operating systems along with exposure to high availability and virtualization solutions. He has a keen interest in shell, Python and Perl scripting and is learning the ropes on AWS cloud, DevOps tools, and methodologies. He enjoys sharing the knowledge he's gained over the years with the rest of the community.