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

Updated:   |  Ansible articles

lower is a Jinja2 filter, used to update a string to all lower case characters. The upper filter is used for all upper case characters. In this example, "Hello World" will be filtered to lower case.

- name: "output 'Hello World' filtered to lower case"
  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, like this.

vars:
  foo: "Hello World"

 

The debug module can be used to output the variable, like this.

- name: "output the contents of the 'foo' variable"
  debug: 
    msg: "{{ foo }}"

 

Which should return the following.

TASK [output the contents of the 'foo' variable]
ok: [server1.example.com] => {
    "msg": [
        "Hello World"
    ]
}

 

The lower filter can be used to update the variable to all lower case characters. Notice that foo is not wrapped in quotes, so that foo is interpreted as a variable, not a string.

- name: "output the contents of the 'foo' variable, lower case"
  debug: 
    msg: "{{ foo | lower }}"

 

Which should return the following.

TASK [output the contents of 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 Buy Me A Coffee



Comments


Add a Comment


Please enter a58a60 in the box below so that we can be sure you are a human.