blockinfile markers

Create markers for Ansible module blockinfile. Mark existing blocks that you want to configure.

Parameters

Parameter

Type

Comments

path

string required

Path to file.

markers

list required

List of dictionaries (see fn/mark-block.yml)

regex1

string required

Regex of block’s beginning.

replace1

string required

Block’s beginning.

regex2

string required

Regex of block’s ending.

replace2

string required

Block’s ending.

Example

For example, in file /usr/local/etc/lighttpd/modules.conf, create blockinfile markers in the following block

##

server.modules = (
  "mod_access",
  #  "mod_alias",
  #  "mod_auth",
  #  "mod_authn_file",
  #  "mod_evasive",
  #  "mod_setenv",
  #  "mod_usertrack",
  #  "mod_redirect",
  #  "mod_rewrite",
  )

##

Create the description of the file (2) and declare the variable for the list of the markers (8)

[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 dictionaries cl_lighttpd_modulesconf_markers (73)

[contrib/lighttpd_nagios/cl-lighttpd.yml]

68# /usr/local/etc/lighttpd/modules.conf
69cl_lighttpd_modulesconf_copy:
70  path: /usr/local/etc/lighttpd/modules.conf.sample
71  remote_src: true
72  force: false
73cl_lighttpd_modulesconf_markers:
74  - marker: server.modules
75    regex1: server.modules\s*=\s*\(
76    replace1: server.modules = (
77    regex2: \)
78    replace2: )

Then, the command

shell> ansible-playbook config-light.yml -t cl_files_copy,cl_files_markers

will copy sample file modules.conf.sample to modules.conf and will create blockinfile markers

##

# BEGIN ANSIBLE MANAGED BLOCK server.modules
server.modules = (
  "mod_access",
#  "mod_alias",
#  "mod_auth",
#  "mod_authn_file",
#  "mod_evasive",
#  "mod_setenv",
#  "mod_usertrack",
#  "mod_redirect",
#  "mod_rewrite",

)
# END ANSIBLE MANAGED BLOCK server.modules

##