
我想使用 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 的編輯器。我用了六在下面的例子中。的價值字串2是用“0”封閉的空格。的價值字串3有 2 個 TAB 以「0」關閉(複製並貼上此處當然刪除了 TAB)。
- 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