Ansible blockinfile モジュールのブロック内でタブを使用する

Ansible blockinfile モジュールのブロック内でタブを使用する

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ブロックはタブを保持します。タブをスペースに置き換えないエディタを使用する必要があります。私は6 六下の例では、文字列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

関連情報