On 14/01/2022 16:17, Jibun no Kage wrote:
New to Ansible, having trouble doing the following:  shell command returns a "This 
is a test\u0000" string.  I can't seem to find a way to trim the '\u0000'.  Since it 
seem to be tricking to remove a backslash literal in Ansible?

The following would work in a shell command...
  cat /proc/device-tree/model | cut -d '\' -f1

But Ansible chokes on the '\'?  And even '\\'  does not work since cut command 
can't handle more than one char.  So the cut parsing trips or Ansible parsing 
trips.  A bit of a catch-22.

Figure there has to be an Ansible elegant way to do this?

Any help appreciated.

 - debug:
     msg: "{{ input | regex_replace('\\\\u0000', '') }}"
   vars:
     input: 'This is a test\u0000'

You might need *four* backslashes to get rid of the original backslash.

But you can get away with *two" by swapping the quotes:

 - debug:
     msg: '{{ input | regex_replace("\\u0000", "") }}'
   vars:
     input: 'This is a test\u0000'

Regards
        Racke


--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 
ansible-project+unsubscr...@googlegroups.com 
<mailto:ansible-project+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a71e1eb3-4ddb-4461-bffd-1a3ea5004e2bn%40googlegroups.com
 
<https://groups.google.com/d/msgid/ansible-project/a71e1eb3-4ddb-4461-bffd-1a3ea5004e2bn%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/87f1ea8a-8d4b-3c3c-de2c-a611fa0cbe05%40linuxia.de.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to