Ansible Module lineinfile

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

The module is mainly used to look for or change a single line in a text file. A typical use case is to ensure that a particular line is in a file, based on a regular expression. Another case is to replace an existing line using a back-referenced regular expression.

Example

- name: "Adjust Java version to {{ jdk.version }}"
  lineinfile:
    path: "{{ settings_path }}/settings.conf"
    regexp: '^JAVA_VERSION='
    line: "JAVA_VERSION={{ jdk.version }}"

Use Cases

Append Lines to a Text File in a Loop