CDIST-TYPE__LINE(7)

πŸ‘‘ cdist-type__line(7) β€” the one where we manage lines in files πŸ’…

okay bestie, so this is a page from the cdist manual β€” it's section 7, and it's all about cdist-type__line, a cdist type that lets you add lines and remove lines from files. that's literally it, and it's iconic for it. ✨


🌸 NAME 🌸

cdist-type__line β€” manage lines in files πŸ¦‹


πŸ’– DESCRIPTION πŸ’–

bestie. this cdist type lets you add lines and remove lines from files. that's the whole vibe. no cap, it just does lines. πŸ”₯


✨ REQUIRED PARAMETERS ✨

None. zero. nada. you don't have to give it anything upfront, she's low maintenance. 🫢


πŸŽ€ OPTIONAL PARAMETERS πŸŽ€

  • after β€” insert the given line after this pattern. iykyk. πŸ’…
  • before β€” insert the given line before this pattern. the prequel energy. 🧚
  • file β€” if you supply this, she uses it as the destination file. otherwise the object_id is used. so like, pick one, she's not gonna guess for you. 🌸
  • line β€” specifies the line which should be absent or present. this is the main character, fr fr.
must be present if state is 'present' or 'replace'. and it gets ignored if regex is given and state is 'absent'. so don't bother setting it there, she's not looking. πŸ’€
  • regex β€” the pattern girlie. here's the tea:
    • if state is 'present', she searches for this pattern and if it matches, she adds the given line. ✨
    • if state is 'absent', she makes sure all lines matching the regular expression are absent. gone. not me deleting them. 😭
    • if state is 'replace', she makes sure all lines matching the regular expression are exactly 'line'. periodt.
the regular expression is interpreted by awk's match function. so write it awk-style, bestie. πŸ”₯
  • state β€” 'present', 'absent' or 'replace'. defaults to 'present' because optimism. 🌈
  • onchange β€” the code to run if the line is added, removed or updated. your little callback bestie. πŸŽ€

πŸ¦‹ BOOLEAN PARAMETERS πŸ¦‹

None. again, nothing. she's simple like that. πŸ™ˆ


⭐ MESSAGES ⭐

  • added β€” the line was added. new line just dropped. πŸŽ‰
  • updated β€” the line or its position was changed. glow up. ✨
  • removed β€” the line was removed. she ate and left no crumbs. πŸ’…

🌈 EXAMPLES 🌈

manage a hosts entry for www.example.com β€” classic.

# Manage a hosts entry for www.example.com.
__line /etc/hosts \
    --line '127.0.0.2 www.example.com'

and another hosts entry for test.example.com, this time with an explicit --file and an object_id that's giving hosts:test.example.com:

# Manage another hosts entry for test.example.com.
__line hosts:test.example.com \
    --file /etc/hosts \
    --line '127.0.0.3 test.example.com'

removing a line? we love a deletion arc. remove the line starting with TIMEZONE from the /etc/rc.conf file:

# Remove the line starting with TIMEZONE from the /etc/rc.conf file.
__line legacy_timezone \
   --file /etc/rc.conf \
   --regex 'TIMEZONE=.*' \
   --state absent

insert a line before another one β€” prequel era:

# Insert a line before another one.
__line password-auth-local:classify \
    --file /etc/pam.d/password-auth-local \
    --line '-session required pam_exec.so debug log=/tmp/classify.log /usr/local/libexec/classify' \
    --before '^session[[:space:]]+include[[:space:]]+password-auth-ac$'

insert a line after another one β€” sequel era:

# Insert a line after another one.
__line password-auth-local:classify \
    --file /etc/pam.d/password-auth-local \
    --line '-session required pam_exec.so debug log=/tmp/classify.log /usr/local/libexec/classify' \
    --after '^session[[:space:]]+include[[:space:]]+password-auth-ac$'

uncomment as needed and set a value in a configuration file β€” the replace state doing her thing:

# Uncomment as needed and set a value in a configuration file.
__line /etc/example.conf \
    --line 'SomeSetting SomeValue' \
    --regex '^(#[[:space:]]*)?SomeSetting[[:space:]]' \
    --state replace

🫢 SEE ALSO 🫢

  • cdist-type(7) β€” go read that one next bestie, it's the lore. πŸ“š

πŸ’œ AUTHORS πŸ’œ

Steven Armstrong <steven-cdist--@--armstrong.cc> β€” the icon, the moment, the legend. πŸ‘‘


πŸ“ COPYING πŸ“

Copyright (C) 2018 Steven Armstrong. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3).


ungleich GmbH 2021


okay that's the whole page bestie, you're so welcome πŸ’…βœ¨

and that's a wrap! this was cdist-type__line(7) from the cdist manual, version 7.0.0, dated Jul 31, 2022. go forth and manage your lines, you absolute main character. πŸ’–πŸŽ€πŸ¦‹πŸŒΈπŸ§šπŸ”₯πŸ‘‘πŸŒˆβ­πŸ’œ

πŸ“¦ where this page comes from