blockinfile
Create or configure blocks in files.
Parameters
Parameter |
Type |
Comments |
|
|---|---|---|---|
path |
string |
Path to file. |
|
blocks |
list |
List of dictionaries (see files-blockinfile.yml) |
|
marker |
string |
Label of the marker. |
|
block |
string |
Text between markers. |
|
… |
… |
<TBD> |
|
owner |
string |
Owner of the file. |
|
group |
string |
Group of the file. |
|
mode |
string |
Mode of the file. |
|
create |
boolean |
Create if does not exist. |
|
validate |
string |
Command to validate file. |
|
handlers |
list |
List of handlers. |
|
Example
Create the description of the file (2) and declare the list of the blocks (10)
[contrib/lighttpd_nagios/conf-light/files.d/lighttpd-modulesconf.yml]
1---
2lighttpd-modulesconf:
3 path: /usr/local/etc/lighttpd/modules.conf
4 create: true
5 owner: root
6 group: wheel
7 mode: "0644"
8 copyfile: "{{ cl_lighttpd_modulesconf_copy }}"
9 markers: "{{ cl_lighttpd_modulesconf_markers }}"
10 lines: "{{ cl_lighttpd_modulesconf_lines }}"
11 blocks: "{{ cl_lighttpd_modulesconf_blocks }}"
12 handlers:
13 - configtest lighttpd
14 - reload lighttpd
Create the list of the blocks cl_lighttpd_modulesconf_blocks (89)
[contrib/lighttpd_nagios/cl-lighttpd.yml]
84cl_lighttpd_modulesconf_server_modules:
85 - mod_access
86 - mod_alias
87 - mod_auth
88 - mod_setenv
89cl_lighttpd_modulesconf_blocks:
90 - marker: server.modules
91 block: |
92 server.modules = (
93 {% for module in cl_lighttpd_modulesconf_server_modules %}
94 "{{ module }}",
95 {% endfor %}
96 )
Then, the command
shell> ansible-playbook config-light.yml -t cl_files_blockinfile
creates this block in modules.conf
##
# BEGIN ANSIBLE MANAGED BLOCK server.modules
server.modules = (
"mod_access",
"mod_alias",
"mod_auth",
"mod_setenv",
)
# END ANSIBLE MANAGED BLOCK server.modules
##
See also
See files-blockinfile.yml annotated source code