小编sol*_*ris的帖子

如何在 Ansible 中添加多行

我试图在比赛后使用 lineinfile 将多行添加到配置文件中,但我发现生成的行是相反的。这是我的剧本:

  - name: Line test
    lineinfile:
      path: /home/vagrant/abcd
      insertafter: '### AFTER THIS LINE'
      line: "{{ item }}"
      state: present
    with_items:
      - '# This is line 1'
      - '# This is line 2'
      - '# This is line 3' 
Run Code Online (Sandbox Code Playgroud)

这是结果:

### AFTER THIS LINE
# This is line 3
# This is line 2
# This is line 1
Run Code Online (Sandbox Code Playgroud)

我想要的结果应该是:

### AFTER THIS LINE
# This is line 1
# This is line 2
# This is line 3 …
Run Code Online (Sandbox Code Playgroud)

ansible

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

ansible ×1