我想修复 VBox 中损坏的发送文件支持,所以我需要将行放入 . 我想用 ansible 剧本来做到这一点。具体任务如下:
- name: fix broken sendfile support in VBox
lineinfile:
dest: /etc/apache2/sites-enabled/000-default
regexp: '^ServerAdmin'
insertafter: 'ServerAdmin'
line: 'EnableSendfile off'
state: present
当我需要再次调用 playbook 时出现问题,并且此任务重复行。如何解决这个问题。
最佳答案
您的任务将在第一次运行时将 ServerAdmin
替换为 EnableSendfile off
,并且在后续运行中它将替换(因为没有 ServerAdmin
可以替换) )将 EnableSendfile
添加到底部。
由于 regexp
是 pattern to replace if found ,您可以尝试将 EnableSendfile 关闭
那里:
- name: fix broken sendfile support in VBox
lineinfile:
dest: /etc/apache2/sites-enabled/000-default
regexp: 'EnableSendfile off'
insertafter: 'ServerAdmin'
line: 'EnableSendfile off'
state: present
关于Ansible lineinfile insertafter 重复行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32254062/