lineinfile

Create or configure lines in a file.

Parameters

Parameter

Type

Comments

path

string required

Path to file.

lines

list required

lineinfile params. Either dict or lines is required.

regexp

string required

Regular expression.

line

string required

Line

backrefs

state

firstmatch

insertafter

insertbefore

<TBD>

assignment

string

Assignment of key and value in dict.

dict

list required

lineinfile params. Either dict or lines is required. (see files-lineinfile.yml)

key

string required

Key value for regexp.

value

string required

Value for line.

firstmatch

insertafter

insertbefore

<TBD>

owner

string

Owner of the file.

group

string

Group of the file.

mode

string

Mode of the file.

attributes

string

Attributes of the file.

other

string

Attributes of module file.

create

boolean

Create file.

validate

string

Command to validate file.

handlers

list

List of handlers.

Example

File /usr/local/etc/dma/dma.conf for DragonFly Mail Agent

[contrib/dma/conf-light/files.d/dma-dmaconf.yml]

1---
2dma_dmaconf:
3  path: /usr/local/etc/dma/dma.conf
4  create: true
5  owner: root
6  group: mail
7  mode: "0644"
8  lines: "{{ cl_dma_dmaconf_lines }}"

[contrib/dma/host_vars/srv.example.com/config-light-dma.yml]

20cl_dma_dmaconf_lines:
21  - { regexp: ^SMARTHOST\s*(.*)$, line: "SMARTHOST {{ cl_dma_smarthost }}" }
22  - { regexp: ^PORT\s*(.*)$, line: "PORT {{ cl_dma_port }}" }
23  - { regexp: ^AUTHPATH\s*(.*)$, line: "AUTHPATH {{ cl_dma_authpath }}" }
24  - { regexp: ^ALIASES\s*(.*)$, line: "ALIASES {{ cl_dma_aliasespath }}" }
25  - { regexp: ^SECURETRANSFER\s*(.*)$, line: SECURETRANSFER }
26  - { regexp: ^STARTTLS\s*(.*)$, line: STARTTLS }
27  - { regexp: ^MASQUERADE\s*(.*)$, line: "MASQUERADE {{ cl_dma_masquerade }}" }

Example of lineinfile with dict

File /usr/local/etc/lighttpd/lighttpd.conf for lighttpd

[contrib/lighttpd/conf-light/files.d/lighttpd-lighttpdconf.yml]

 1---
 2lighttpd-lighttpdconf:
 3  path: /usr/local/etc/lighttpd/lighttpd.conf
 4  create: true
 5  owner: root
 6  group: wheel
 7  mode: "0644"
 8  assignment: " = "
 9  dict: "{{ cl_lighttpd_lighttpdconf_dict }}"
10  handlers:
11    - reload lighttpd

[contrib/lighttpd/host_vars/srv.example.com/cl-lighttpd.yml]

10cl_lighttpd_server_document_root: /usr/local/www/lighttpd
11cl_lighttpd_lighttpdconf_dict:
12  - { key: server.port, value: '"{{ cl_lighttpd_server_port }}"' }
13  - { key: server.use-ipv6, value: '"{{ cl_lighttpd_server_useipv6 }}"' }
14  - { key: server.username, value: '"{{ cl_lighttpd_server_username }}"' }
15  - { key: server.groupname, value: '"{{ cl_lighttpd_server_groupname }}"' }

See also