'how to remove space from variable in ansible?

I would like to know how to remove space from a variable or item in ansible.

I have a file with aline like this:

abc de fg

I do:

- name: set fact
  set_fact:
    output: "{{ item }}"
  with_lines: /path/to/file

From example I get the following debug output:

ok: [localhost] => (item=abc de fg) => {"ansible_facts": {"servicename": "abc de fg"}, "ansible_loop_var": "item", "changed": false, "item": "abc de fg"}

I'd like to change it to:

ok: [localhost] => (item=abcdefg) => {"ansible_facts": {"servicename": "abcdefg"}, "ansible_loop_var": "item", "changed": false, "item": "abcdefg"}`.

I know I can add a task like:

- command: sed -i 's/ //g' file

Before the task but I would like to know if there is another way.

Best regards.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source