whitespace in stdout

hello, I am having a hard time finding anything in google on how to remove whitespace from the stdout results.

Here is the play:

tasks:

  • name: get droplet IPs from inventory
    shell: ansible -i hosts testing --list-hosts
    register: droplet_inventory

  • debug: msg=“{{ item|e - }}”

with_items: “{{ droplet_inventory.stdout_lines}}”

output:

ok: [localhost] => (item= 10.128.164.13) => {

“item”: " 10.128.164.13",

“msg”: " 10.128.164.13"

}

ok: [localhost] => (item= 10.128.163.87) => {

“item”: " 10.128.163.87",

“msg”: " 10.128.163.87"

}

ok: [localhost] => (item= 10.128.163.89) => {

“item”: " 10.128.163.89",

“msg”: " 10.128.163.89"

}

ok: [localhost] => (item= 10.128.163.90) => {

“item”: " 10.128.163.90",

“msg”: " 10.128.163.90"

}

How can I get rid of the leading whitespace?

For now I solved this with:

  • debug: msg={{ item|replace(’ ‘,’') }}
    with_items: “{{ droplet_inventory.stdout_lines}}”

if anyone knows a better method please share.

Unclear why you need to remove whitespace from output, can you explain your use case?