using tabs within block for ansible blockinfile module
I want to output some text with tab as separator using ansible
here’s task snippet
- name: Create output file
blockinfile:
block: |
Some texttmore text
path: '{{ playbook_dir }}/output.txt'
create: true
CURRENT OUTPUT
# BEGIN ANSIBLE MANAGED BLOCK
Some texttmore text
# END ANSIBLE MANAGED BLOCK
DESIRED
# BEGIN ANSIBLE MANAGED BLOCK
Some text more text
# END ANSIBLE MANAGED BLOCK
The YAML blocks preserve TAB. You have to use an editor that doesn’t replace TAB with spaces. I used vi in the below example. The value of str2 are spaces closed with ‘0’. The value of str3 are 2 TAB(s) closed with ‘0’ (copy&paste here removed the TAB(s) of course).
- hosts: localhost
vars:
str1: |
01234567890
str2: |
0 0
str3: |
0 0
tasks:
- debug:
msg:
str1 {{ str1|length }} {{ str1 }}
str2 {{ str2|length }} {{ str2 }}
str3 {{ str3|length }} {{ str3 }}
gives abridged
msg: |-
str1 12 01234567890
str2 12 0 0
str3 5 0 0