【发布时间】:2020-09-16 00:11:25
【问题描述】:
我正在寻找一种在 Ansible (2.9) 中将文本文件中的一行移动到文件末尾的方法。
line 1
line 2
line at end of file
line 3
line 4
应该变成
line 1
line 2
line 3
line 4
line at end of file
lineinfile 模块可以在末尾添加新行,但如果该行已经存在,则不会移动它。
# This does not move an existing line
- name: Move line to end of file
lineinfile:
path: /etc/myfile
line: 'line at end of file'
insertafter: EOF
我目前的解决方案是先去掉行,然后重新添加,但这当然不是幂等的,每次运行都会导致两次变化。
【问题讨论】:
标签: ansible