gpt4 book ai didi

yaml - 使用ansible编辑多个目标文件?

转载 作者:行者123 更新时间:2023-12-02 04:46:04 24 4
gpt4 key购买 nike

我目前正在尝试更新多台服务器上的所有 wp-config.php 文件。下面这个应该可以工作,但它不允许我使用正则表达式作为目的地。

有人知道执行此操作的替代方法吗?

---
- hosts: blah.blah.net
user: blah
sudo: true
tasks:
- name: add a new string before the match
lineinfile: dest='\/home\/.*\/public_html\/wp-config.php'
regexp='^\/\*\* MySQL database password \*\/'
insertbefore='^\/\*\* MySQL database password \*\/'
line='define("DISALLOW_FILE_MODS", true);'

最佳答案

如您所见,正则表达式在那里不起作用。我推荐的是像这样使用 with_items:

- name: add a new string before the match
lineinfile: dest=/home/{{ item }}/public_html/wp-config.php
regexp=' ... '
with_items:
- usera
- userb
- userc

您可以从文件中获取项目列表(with_lines: cat filename)或通过远程获取它们(即从受管节点),比方说,shell Action 和一个 register: variable

关于yaml - 使用ansible编辑多个目标文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19782012/

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