2

我目前正在尝试更新多台服务器上的所有 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);'
4

1 回答 1

5

As you've already experienced, a regular expression won't work there. What I recommend is to use with_items like this:

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

You can obtain a list of items from a file (with_lines: cat filename) or by obtaining them remotely (i.e. from the managed nodes) with, say, a shell action and a register: variable.

于 2013-11-16T09:38:36.357 回答