替换小写或大写字符串

我正在写一部剧本,以替换三个文件中的字符串。该字符串可以小写或大写。这是我的代码:

---
  - name: "Modif string"
    hosts: myhosts
    tasks:
    - name: "Replace line"
      replace:
        path: ~/Documents/{{ item  }}
        regexp: 'test'
        replace: 'new'
      with_items:
      - 'file'
      - 'file1'
      - 'file2'

我如何使其起作用,以便对字符串“ test”进行修改(无论是小写还是大写)?如果该字符串中随机存在字母大写或小写怎么办?

谢谢大家。

yangyaolei 回答:替换小写或大写字符串

尝试如下

  - name: "Replace line"
    replace:
      path: ~/Documents/{{ item  }}
      regexp: '(?i)test'
      replace: 'new'
,

我终于写了那个脚本。就像魅力一样。

- name: "Other test"
  hosts: raspi
  vars:
    text_to_replace:
      - {regexp: '(?i)(test)',line: 'new'}
      - {regexp: '10',line: '20'}
    my_files:
      - {file: 'file'}
      - {file: 'file1'}
      - {file: 'file2'}
  tasks:
    - name: "Replace"
      replace:
        path: ~/test/{{item.1.file}}
        regexp: "{{item.0.regexp}}"
        replace: "{{item.0.line}}"
      with_nested:
        - "{{text_to_replace}}"
        - "{{my_files}}"
本文链接:https://www.f2er.com/3159542.html

大家都在问