ansible:几行的lineinfile? [英] ansible: lineinfile for several lines?
本文介绍了ansible:几行的lineinfile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
同一个模块lineinfile
在一个文件中添加一行,有没有办法添加多行?
The same way there is a module lineinfile
to add one line in a file, is there a way to add several lines?
我不想使用模板,因为您必须提供整个文件.我只想在现有文件中添加一些内容,而不必知道文件已包含的内容,因此无法选择模板.
I do not want to use a template because you have to provide the whole file. I just want to add something to an existing file without necessarily knowing what the file already contains so a template is not an option.
推荐答案
您可以使用 lineinfile
内置在 循环.举个例子:
You can use the lineinfile
built-in in a loop. Here's an example:
- name: Set some kernel parameters
lineinfile:
dest: /etc/sysctl.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
loop:
- { regexp: '^kernel.shmall', line: 'kernel.shmall = 2097152' }
- { regexp: '^kernel.shmmax', line: 'kernel.shmmax = 134217728' }
- { regexp: '^fs.file-max', line: 'fs.file-max = 65536' }
这篇关于ansible:几行的lineinfile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文