I have a configuration file /etc/csync/csync2.cfg with a format as this,
group ha_group
{
key /etc/csync2/key_hagroup;
host host1;
host host2;
include /etc/booth;
include /etc/corosync/corosync.conf;
include /etc/corosync/authkey;
}
I want to figure out if an entry exists(e.g. include /var/tsm/tsm/tsm.conf;). If it does, do nothing and if not, add it.
I've checked poise-file and line cookbooks in the chef supermarket. Problem with the actions provided in those cookbooks is if the entry is not present, they add it to the end of the file.
My usecase requires it to be added within the braces {} and not the end of the file.
I cannot template the file because the contents of /etc/csync/csync2.cfg may vary from node to node.
Another alternative was checking if the csync2 command line has any option to add new entries https://github.com/LINBIT/csync2/blob/master/doc/csync2.adoc to avoid processsing in recipe
you might find poise-file, line cookbooks handy or use FileEdit directly