Ansible - Update a value to lower case using the lower filter

by
Jeremy Canfield |
Updated: June 01 2025
| Ansible articles
There are a few different filters that can be used to update a value to uppercase or lowercase.
- lower is a Jinja2 filter to update a string to all lowercase characters (this article)
- upper is a Jinja2 filter to update a string to all uppercase characters
- title is a Jinja2 filter to update the first character in a string to uppercase
- capatalize is a Jinja2 filter to update the first character in a string to uppercase
In this example, "Hello World" will be filtered to lower case.
---
- hosts: all
tasks:
- name: output 'Hello World' filtered to lower case
ansible.builtin.debug:
msg: "{{ 'Hello World' | lower }}"
...
Which should return the following.
TASK [output 'Hello World' filtered to lower case]
ok: [server1.example.com] => {
"msg": [
"hello world"
]
}
Let's say you are using the vars plugin to create a variable. The debug module can be used to output the variable, like this.
---
- hosts: all
vars:
foo: "Hello World"
tasks:
- name: output the 'foo' variable
ansible.builtin.debug:
msg: "{{ foo }}"
...
Which should return the following.
TASK [output the 'foo' variable]
ok: [server1.example.com] => {
"msg": [
"Hello World"
]
}
The lower filter can be used to update the variable to all lowercase characters. Notice that foo is not wrapped in quotes, so that foo is interpreted as a variable, not a string.
---
- hosts: all
vars:
foo: "Hello World"
tasks:
- name: output the 'foo' variable, lower case
ansible.builtin.debug:
msg: "{{ foo | lower }}"
...
Which should return the following.
TASK [output the 'foo' variable, lower case]
ok: [server1.example.com] => {
"msg": [
"hello world"
]
}
Did you find this article helpful?
If so, consider buying me a coffee over at
Comments
August 21 2024 by Dora
Thank you! This is a nice answer to find in a Google search. Concise and practical :)