ansible:lineinfile 有多行?

标签 ansible

同样,有一个模块lineinfile可以在文件中添加一行,有没有办法添加多行?

我不想使用模板,因为您必须提供整个文件。 我只想向现有文件添加一些内容,而不必知道该文件已包含什么内容,因此模板不是一个选项。

最佳答案

您可以使用lineinfile built-inloop 。这是一个例子:

- 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 有多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24334115/

相关文章:

bash - Ansible 输出格式化选项

shell 模块 : < with ansible

variables - Ansible - 更新 vars_file 中的变量并在剧本中再次调用它不起作用

yaml - ansible with_items 列表列表正在变平

shell - ansible playbook命令中的问题?

ansible - 通过 Ansible 从 A nexus repo 获取最新的 war 文件

linux - Ansible 备份文件名

permissions - 使用 Ansible 创建 GCE 实例,权限问题

ansible - 如何在 Ubuntu 18.04 上完全删除 Ansible 2.8.3

kubernetes - 目标/etc/default/kubelet 不存在