From 957679db3c6eccdb51facce918a3ab7f274a32bc Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 15 Oct 2021 16:24:22 -0400 Subject: [PATCH] Update syncfile examples and el7 support --- .../profiles/default/scripts/syncfileclient | 20 ++++++++++++++++++- .../el7/profiles/default/syncfiles | 10 +++++++++- .../el8-diskless/profiles/default/syncfiles | 10 +++++++++- .../el8/profiles/default/syncfiles | 10 +++++++++- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/confluent_osdeploy/el7/profiles/default/scripts/syncfileclient b/confluent_osdeploy/el7/profiles/default/scripts/syncfileclient index 234a458e..6e50a4f9 100644 --- a/confluent_osdeploy/el7/profiles/default/scripts/syncfileclient +++ b/confluent_osdeploy/el7/profiles/default/scripts/syncfileclient @@ -198,11 +198,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 = '' @@ -230,6 +245,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', {}) diff --git a/confluent_osdeploy/el7/profiles/default/syncfiles b/confluent_osdeploy/el7/profiles/default/syncfiles index d8283e3e..0f7d6e4e 100644 --- a/confluent_osdeploy/el7/profiles/default/syncfiles +++ b/confluent_osdeploy/el7/profiles/default/syncfiles @@ -5,7 +5,15 @@ # If wanting to simply use the same path for source and destinaiton, the -> may be skipped: # /etc/hosts -# Entries under MERGE will attempt to be intelligently merged. This supports /etc/group and /etc/passwd +# More function is available, for example to limit the entry to run only on n1 through n8, and to set +# owner, group, and permissions in octal notation: +# /example/source -> n1-n8:/etc/target (owner=root,group=root,permissions=600) + +# Entries under APPENDONCE: will be added to specified target, only if the target does not already +# contain the data in the source already in its entirety. This allows append in a fashion that +# is friendly to being run repeatedly + +# Entries under MERGE: will attempt to be intelligently merged. This supports /etc/group and /etc/passwd # Any supporting entries in /etc/shadow or /etc/gshadow are added automatically, with password disabled # It also will not inject 'system' ids (under 1,000 usually) as those tend to be local and rpm managed. MERGE: diff --git a/confluent_osdeploy/el8-diskless/profiles/default/syncfiles b/confluent_osdeploy/el8-diskless/profiles/default/syncfiles index d8283e3e..0f7d6e4e 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/syncfiles +++ b/confluent_osdeploy/el8-diskless/profiles/default/syncfiles @@ -5,7 +5,15 @@ # If wanting to simply use the same path for source and destinaiton, the -> may be skipped: # /etc/hosts -# Entries under MERGE will attempt to be intelligently merged. This supports /etc/group and /etc/passwd +# More function is available, for example to limit the entry to run only on n1 through n8, and to set +# owner, group, and permissions in octal notation: +# /example/source -> n1-n8:/etc/target (owner=root,group=root,permissions=600) + +# Entries under APPENDONCE: will be added to specified target, only if the target does not already +# contain the data in the source already in its entirety. This allows append in a fashion that +# is friendly to being run repeatedly + +# Entries under MERGE: will attempt to be intelligently merged. This supports /etc/group and /etc/passwd # Any supporting entries in /etc/shadow or /etc/gshadow are added automatically, with password disabled # It also will not inject 'system' ids (under 1,000 usually) as those tend to be local and rpm managed. MERGE: diff --git a/confluent_osdeploy/el8/profiles/default/syncfiles b/confluent_osdeploy/el8/profiles/default/syncfiles index d8283e3e..0f7d6e4e 100644 --- a/confluent_osdeploy/el8/profiles/default/syncfiles +++ b/confluent_osdeploy/el8/profiles/default/syncfiles @@ -5,7 +5,15 @@ # If wanting to simply use the same path for source and destinaiton, the -> may be skipped: # /etc/hosts -# Entries under MERGE will attempt to be intelligently merged. This supports /etc/group and /etc/passwd +# More function is available, for example to limit the entry to run only on n1 through n8, and to set +# owner, group, and permissions in octal notation: +# /example/source -> n1-n8:/etc/target (owner=root,group=root,permissions=600) + +# Entries under APPENDONCE: will be added to specified target, only if the target does not already +# contain the data in the source already in its entirety. This allows append in a fashion that +# is friendly to being run repeatedly + +# Entries under MERGE: will attempt to be intelligently merged. This supports /etc/group and /etc/passwd # Any supporting entries in /etc/shadow or /etc/gshadow are added automatically, with password disabled # It also will not inject 'system' ids (under 1,000 usually) as those tend to be local and rpm managed. MERGE: