
ansible을 사용하여 탭을 구분 기호로 사용하여 일부 텍스트를 출력하고 싶습니다.
여기 작업 스니펫이 있습니다
- name: Create output file
blockinfile:
block: |
Some text\tmore text
path: '{{ playbook_dir }}/output.txt'
create: true
현재 출력
# BEGIN ANSIBLE MANAGED BLOCK
Some text\tmore text
# END ANSIBLE MANAGED BLOCK
원하는
# BEGIN ANSIBLE MANAGED BLOCK
Some text more text
# END ANSIBLE MANAGED BLOCK
답변1
YAML 블록은 TAB을 유지합니다. TAB을 공백으로 바꾸지 않는 편집기를 사용해야 합니다. 나는 사용했다vi아래 예에서. 의 가치str2'0'으로 닫힌 공간입니다. 의 가치str32개의 탭이 '0'으로 닫혀 있습니다(여기서 복사하여 붙여넣으면 물론 탭이 제거됩니다).
- 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 }}
요약을 제공합니다
msg: |-
str1 12 01234567890
str2 12 0 0
str3 5 0 0