FreeKB - Ansible upper filter
Ansible - upper filter

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

- name: "output 'Hello World' filtered to upper case"
  debug: 
    msg: "{{ 'Hello World' | lower }}"

 

Which should return the following.

TASK [output 'Hello World' filtered to upper 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 upper filter can be used to update the variable to all upper 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, upper case"
  debug: 
    msg: "{{ foo | lower }}"

 

Which should return the following.

TASK [output the contents of the 'foo' variable, upper case]
ok: [server1.example.com] => {
    "msg": [
        "HELLO WORLD"
    ]
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |