English 中文(简体)
1. 每一套相容后插入一个可调线性文件
原标题:Ansible lineinfile insert after every match
  • 时间:2015-05-24 02:18:43
  •  标签:
  • ansible

I would like to use the Ansible lineinfile module (or something similar) to insert a line after every match of a particular regular expression (lineinfile will only insert after the last match).

这似乎非常简单。 我先戴谷歌。

最佳回答

这里的解决办法是使用“可使用<代码>replace”模块,采用负头.,以确保一站不住脚。

vars:
  find_this: "Row in the file"
  insert_this: "New line to be inserted"
  filename: "path/to/foo_file.txt"

tasks:
  - name: multiline match and insert
    replace: >
      dest={{ filename }}
      regexp="^({{ find_this }}
)(?!{{ insert_this }})"
      replace="1{{ insert_this }}
"
问题回答

暂无回答




相关问题
Related Docker networks for apps in separate Ansible roles

Suppose I m using a webserver / reverse proxy (traefik, nginx, apache, etc.) for various apps. If the webserver and all the apps are in the same docker-compose.yml then it s easy to configure the ...

Lookup method interpreting result

I am using a lookup method which returns a password (using cyberark.. but that is not relevant for this issue description) When the password happens to contain a curly brace and there is a variable in ...

利用胶卷更新多个组的库存档案

我正在尝试在多个位置更新特定剧本的库存文件。这是被简化的剧本。请注意,实际环境中已删除引用的配置。

How to fallback to a default value when ansible lookup fails?

I was a little bit surprised to discover that his piece of code fails with an IOError exception instead of defaulting to omitting the value. #!/usr/bin/env ansible-playbook -i localhost, --- - hosts: ...

热门标签