2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-03-22 10:09:17 +00:00

Fix some issues from async ansible running

This commit is contained in:
Jarrod Johnson
2026-03-13 11:40:44 -04:00
parent fed83841bb
commit 2c8cce74ab
3 changed files with 8 additions and 8 deletions

View File

@@ -3,7 +3,7 @@ import confluent.messages as msg
import confluent.runansible as runansible
_user_initiated_runs = {}
def update(nodes, element, configmanager, inputdata):
async def update(nodes, element, configmanager, inputdata):
if element[-1] != 'run':
raise ValueError('Invalid element for remoteconfig plugin')
for node in nodes:
@@ -11,13 +11,13 @@ def update(nodes, element, configmanager, inputdata):
playlist = selfservice.list_ansible_scripts(configmanager, node, category)
if playlist:
_user_initiated_runs[node] = True
runansible.run_playbooks(playlist, [node])
await runansible.run_playbooks(playlist, [node])
yield msg.CreatedResource(
'/nodes/{0}/deployment/remote_config/active/{0}'.format(node))
else:
yield msg.ConfluentNodeError('No remote configuration for category "{0}"', node)
def retrieve(nodes, element, configmanager, inputdata):
async def retrieve(nodes, element, configmanager, inputdata):
for node in nodes:
if element[-1] == 'active':
rst = runansible.running_status.get(node, None)

View File

@@ -96,7 +96,7 @@ class PlayRunner(object):
if ansloc:
with open(ansloc, 'r') as onsop:
shebang = onsop.readline()
anspypath = shebang.strip().replace('#!', '')
anspypath = shebang.strip().replace('#!', '').strip()
mypath = anspypath
if not mypath:
mypath = sys.executable
@@ -119,8 +119,8 @@ class PlayRunner(object):
self.complete = True
def run_playbooks(playfiles, nodes):
sshutil.prep_ssh_key('/etc/confluent/ssh/automation')
async def run_playbooks(playfiles, nodes):
await sshutil.prep_ssh_key('/etc/confluent/ssh/automation')
runner = PlayRunner(playfiles, nodes)
for node in nodes:
running_status[node] = runner

View File

@@ -493,7 +493,7 @@ async def handle_request(req, make_response, mimetype):
if filename.endswith('.yaml') or filename.endswith('.yml'):
playlist.append(os.path.join(dirname, filename))
if playlist:
runansible.run_playbooks(playlist, [nodename])
await runansible.run_playbooks(playlist, [nodename])
return await make_response(mimetype, 202, 'Queued', body='Queued')
else:
return await make_response(mimetype, 200, 'OK', body='OK')
@@ -516,7 +516,7 @@ async def handle_request(req, make_response, mimetype):
mrsp = await make_response(mimetype, 200, 'OK')
if rst.complete:
del runansible.running_status[nodename]
await mrsp.write(rst.dump_text())
await mrsp.write(rst.dump_text().encode('utf8'))
return mrsp
elif reqpath.startswith('/self/scriptlist/'):
scriptcat = reqpath.replace('/self/scriptlist/', '')