gpt4 book ai didi

ansible - 用 ansible 替换配置文件中的一行

转载 作者:行者123 更新时间:2023-12-03 23:22:50 25 4
gpt4 key购买 nike

我是ansible的新手。

有没有一种简单的方法来替换以 option domain-name-servers 开头的行在 /etc/dhcp/interface-br0.conf有更多的IP?

  option domain-name-servers 10.116.184.1,10.116.144.1;

我要加 ,10.116.136.1

最佳答案

您可以使用 lineinfile Ansible module实现这一目标。

  - name: replace line
lineinfile:
path: /etc/dhcp/interface-br0.conf
regexp: '^(.*)option domain-name-servers(.*)$'
line: 'option domain-name-servers 10.116.184.1,10.116.144.1,10.116.136.1;'
backrefs: yes
regexp选项告诉模块要替换的内容是什么。 line选项将先前找到的内容替换为您选择的新内容。 backrefs选项保证如果正则表达式不匹配,文件将保持不变。

关于ansible - 用 ansible 替换配置文件中的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40788575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com