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ブロックはTABを保持します。 TABを空白に置き換えないエディタを使用する必要があります。使った以下の例では。の価値文字列2「0」で囲まれたスペースです。の価値文字列3「0」で閉じたタブが2つあります(もちろんここにコピーして貼り付けるとタブが削除されます)。

- 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

おすすめ記事