Ansible lineinfile insertafter 重复行

标签 ansible idempotent

我想修复 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 添加到底部。 由于 regexppattern 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/

相关文章:

domain-driven-design - 在使用事件溯源时使用聚合版本号是幂等的

apache-kafka - Kafka Mirromaker2 生产者幂等性和重复项

docker - 是否有将 ansible-playbook 转换为 Dockerfile 的工具?

linux - 无法在 shell 脚本内运行 ansible 命令

cron - 在 crontab 中拥有多个 MAILTO 环境变量的可靠方法

Ansible 远程模板

ruby-on-rails - Sidekiq 幂等性、N+1 查询和死锁

ansible - ansible playbook 中的幂等性

ansible - 如何从 Ansible with_subelements 列表中对项目进行排序