Ansible Pilot

Automating Text Capitalization with Ansible Playbooks

Streamlining Text Processing Through Ansible Automation

January 4, 2024
Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons


In the realm of IT automation, Ansible stands out as a powerful tool for configuring, managing, and deploying infrastructure. Its simplicity and flexibility make it a favorite among system administrators and DevOps professionals. In this article, we’ll explore a practical example that goes beyond the conventional server configurations. We’ll delve into using Ansible to automate the capitalization of text.

Introduction to Ansible Playbooks

Ansible Playbooks are configuration files written in YAML that define a set of tasks to be executed on remote hosts. These playbooks enable automation across various systems, making them an excellent choice for handling repetitive tasks. In this example, we have a simple Ansible Playbook named capitalize.yml that capitalizes a given text.

- name: Capitalize
  hosts: all
  gather_facts: false
    my_text: "hello world"
    - name: Print message on the screen
        msg: "{{ my_text | capitalize }}"

Let’s break down the key components of this playbook:

The Localhost Inventory File

In Ansible, the inventory file specifies the hosts on which the playbook will run. In our case, the inventory file (inventory) contains a single line defining the localhost with the connection set to local. This means the playbook will be executed on the local machine.

localhost ansible_connection=local

The Best Resources For Ansible


Video Course

Printed Book


Running the Playbook

Executing the playbook is straightforward. Using the ansible-playbook command with the -i flag to specify the inventory file, we run:

$ ansible-playbook -i inventory capitalize.yml

Upon running the playbook, Ansible processes the defined tasks and provides feedback on the execution. In the example output you provided:

PLAY [Capitalize] ***********************************************************************
TASK [Print message on the screen] ******************************************************
ok: [localhost] => {
    "msg": "Hello world"
PLAY RECAP ******************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

The output confirms that the task was successfully executed on the localhost host, and the message “Hello world” was printed on the screen.

Customizing the Playbook

You can easily adapt this playbook to capitalize different text by modifying the my_text variable. Additionally, you can extend the playbook to capitalize text from external sources, such as files or dynamic inventories.


This example demonstrates the versatility of Ansible in automating not only system configurations but also text processing tasks. By leveraging Ansible Playbooks, you can efficiently handle various automation scenarios, making it a valuable tool in the toolkit of any IT professional.

Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.


Learn the Ansible automation technology with some real-life examples in my

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons
Follow me

Subscribe not to miss any new releases