ansible:lineinfile有几行? [英] ansible: lineinfile for several lines?

查看:78
本文介绍了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.

推荐答案

您可以使用循环做到这一点.这是使用with_items循环的示例:

You can use a loop to do it. Here's an example using a with_items loop:

- name: Set some kernel parameters
  lineinfile:
    dest: /etc/sysctl.conf
    regexp: "{{ item.regexp }}"
    line: "{{ item.line }}"
  with_items:
    - { 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆