diff --git a/confluent_osdeploy/el8/profiles/default/scripts/syncfileclient b/confluent_osdeploy/el8/profiles/default/scripts/syncfileclient index 5638244d..3fdd1f08 100644 --- a/confluent_osdeploy/el8/profiles/default/scripts/syncfileclient +++ b/confluent_osdeploy/el8/profiles/default/scripts/syncfileclient @@ -192,11 +192,26 @@ class CredMerger: continue shadout.write(name + ':!::\n') +def appendonce(basepath, filename): + with open(filename, 'rb') as filehdl: + thedata = filehdl.read() + targname = filename.replace(basepath, '') + try: + with open(targname, 'rb') as filehdl: + targdata = filehdl.read() + except IOError: + targdata = b'' + if thedata in targdata: + return + with open(targname, 'ab') as targhdl: + targhdl.write(thedata) + def synchronize(): tmpdir = tempfile.mkdtemp() + appendoncedir = tempfile.mkdtemp() try: ac = apiclient.HTTPSClient() - data = json.dumps({'merge': tmpdir}) + data = json.dumps({'merge': tmpdir, 'appendonce': appendoncedir}) status, rsp = ac.grab_url_with_status('/confluent-api/self/remotesyncfiles', data) if status == 202: lastrsp = '' @@ -224,6 +239,9 @@ def synchronize(): cm.read_source(pendhosts) cm.read_target('/etc/hosts') cm.write_out('/etc/hosts') + for dirn in os.walk(appendoncedir): + for filen in dirn[2]: + appendonce(appendoncedir, os.path.join(dirn[0], filen)) if lastrsp: lastrsp = json.loads(lastrsp) opts = lastrsp.get('options', {}) @@ -247,6 +265,7 @@ def synchronize(): os.chown(fname, uid, gid) finally: shutil.rmtree(tmpdir) + shutil.rmtree(appendoncedir) if __name__ == '__main__': diff --git a/confluent_server/confluent/syncfiles.py b/confluent_server/confluent/syncfiles.py index 8f7d455d..3dddfe8b 100644 --- a/confluent_server/confluent/syncfiles.py +++ b/confluent_server/confluent/syncfiles.py @@ -37,6 +37,7 @@ class SyncList(object): slist = None self.replacemap = {} self.appendmap = {} + self.appendoncemap = {} self.mergemap = {} self.optmap = {} with open(filename, 'r') as slfile: @@ -59,6 +60,8 @@ class SyncList(object): if ent[-1] == ':': if ent == 'MERGE:': currmap = self.mergemap + elif ent == 'APPENDONCE:': + currmap = self.appendoncemap else: raise Exception( 'Section "{}" is not currently supported in syncfiles'.format(ent[:-1])) @@ -132,6 +135,12 @@ def sync_list_to_node(sl, node, suffixes): for ent in sl.mergemap: stage_ent(sl.mergemap, ent, os.path.join(targdir, suffixes['merge']), True) + if 'appendonce' in suffixes: + while suffixes['appendonce'] and suffixes['appendonce'][0] == '/': + suffixes['appendonce'] = suffixes['appendonce'][1:] + for ent in sl.appendoncemap: + stage_ent(sl.appendoncemap, ent, + os.path.join(targdir, suffixes['appendonce']), True) sshutil.prep_ssh_key('/etc/confluent/ssh/automation') output = subprocess.check_output( ['rsync', '-rvLD', targdir + '/', 'root@{}:/'.format(node)], timeout=86400)