Adding Single Line to File with SaltStack
I would like to add the following lines to all /etc/sudoers files across my environment:
# Administrators LDAP Group
%Administrators ALL=(ALL) ALL
However, each server has a different /etc/sudoers file, and sourcing them all from one location would be impractical.
Is there a way in Salt to ensure a single line (or group of lines) exists in a file, rather than managing that whole file?
You are probably looking for file.append.
File.append searches the whole file and if it is unable to find your text, it will append it to the end of the file. I am assuming that you don't know of any common text structures in you /etc/sudoers file so you won't be able to use something like file.sed to replace some text.
Sample Code:
/etc/sudoers:
file.append:
- text:
- "# Administrators LDAP Group"
- "%Administrators ALL=(ALL) ALL"
NOTE: You should probably test the sample code before you use it.