@@ -1076,6 +1076,59 @@ bundle edit_line converge(marker, lines)
10761076 "$(lines)" comment => "Insert the given lines";
10771077}
10781078
1079+ bundle edit_line converge_prepend(marker, lines)
1080+ # @brief Converge `lines` marked with `marker` to start of content.
1081+ #
1082+ # Any content marked with `marker` is removed, then `lines` are
1083+ # inserted at *start* of content. Every `line` should contain `marker`.
1084+ #
1085+ # This is helpful for files where order matters, like `pam.d/common-auth`,
1086+ # and you want the content at the top. If you want to maintain the order
1087+ # of multiple lines, pass one item with a newline in it like this:
1088+ #
1089+ # **Example:**
1090+ #
1091+ # ```cf3
1092+ # files:
1093+ # "/etc/pam.conf"
1094+ # edit_line => converge_prepend("session", "session required pam_loginuid.so
1095+ #session required pam_env.so
1096+ #session required pam_env.so envfile=/etc/default/locale
1097+ #session required pam_limits.so");
1098+ # ```
1099+ #
1100+ # @param marker The marker (not a regular expression; will be escaped)
1101+ # @param lines The lines to insert; all must contain `marker`
1102+ #
1103+ # **Example:**
1104+ #
1105+ # ```cf3
1106+ # bundle agent pam_d_su_session
1107+ # # @brief Ensure /etc/pam.d/su has session configured properly
1108+ # {
1109+ # files:
1110+ # ubuntu::
1111+ # "/etc/pam.d/su"
1112+ # edit_line => converge_prepend( "session", "session required pam_env.so readenv=1 envfile=/etc/default/locale
1113+ # session optional pam_mail.so nopen
1114+ # session required pam_limits.so" );
1115+ # }
1116+ # ```
1117+ #
1118+ # **History:**
1119+ #
1120+ # * Introduced in 3.17.0
1121+ {
1122+ vars:
1123+ "regex" string => escape($(marker));
1124+
1125+ delete_lines:
1126+ ".*$(regex).*" comment => "Delete lines matching the marker";
1127+ insert_lines:
1128+ "$(lines)" location => start, comment => "Insert the given lines";
1129+ }
1130+
1131+
10791132bundle edit_line fstab_option_editor(method, mount, option)
10801133# @brief Add or remove `/etc/fstab` options for a mount
10811134#
0 commit comments