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?
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'
You haven’t posted any Ansible for us to help you with. Could you include something you think should work but doesn’t? Otherwise we’re just guessing what you’re trying to do, and that rarely works well for anybody.