Browse Source

fix: 修复 ansible receptor playbook 无法执行的问题

pull/12985/head
Aaron3S 8 months ago committed by Bryan
parent
commit
2b05fd5276
  1. 2
      apps/jumpserver/conf.py
  2. 10
      apps/ops/ansible/runner.py
  3. 5
      apps/ops/models/job.py
  4. 2
      jms

2
apps/jumpserver/conf.py

@ -618,7 +618,7 @@ class Config(dict):
# Ansible Receptor
'ANSIBLE_RECEPTOR_ENABLE': True,
'ANSIBLE_RECEPTOR_SOCK_PATH': 'data/share/control.sock'
'ANSIBLE_RECEPTOR_SOCK_PATH': '{}/data/share/control.sock'.format(PROJECT_DIR)
}
old_config_map = {

10
apps/ops/ansible/runner.py

@ -87,6 +87,7 @@ class AdHocRunner:
class PlaybookRunner:
def __init__(self, inventory, playbook, project_dir='/tmp/', callback=None):
self.id = uuid.uuid4()
self.inventory = inventory
self.playbook = playbook
@ -96,7 +97,16 @@ class PlaybookRunner:
self.cb = callback
self.envs = {}
def copy_playbook(self):
entry = os.path.basename(self.playbook)
playbook_dir = os.path.dirname(self.playbook)
project_playbook_dir = os.path.join(self.project_dir, "project")
shutil.copytree(playbook_dir, project_playbook_dir)
self.playbook = entry
def run(self, verbosity=0, **kwargs):
self.copy_playbook()
verbosity = get_ansible_log_verbosity(verbosity)
private_env = safe_join(self.project_dir, 'env')
if os.path.exists(private_env):

5
apps/ops/models/job.py

@ -339,7 +339,9 @@ class JobExecution(JMSOrgBaseModel):
)
elif self.current_job.type == Types.playbook:
runner = PlaybookRunner(
self.inventory_path, self.current_job.playbook.entry
self.inventory_path,
self.current_job.playbook.entry,
self.private_dir
)
elif self.current_job.type == Types.upload_file:
job_id = self.current_job.id
@ -522,7 +524,6 @@ class JobExecution(JMSOrgBaseModel):
ssh_tunnel.local_gateway_clean(runner)
def stop(self):
unit_id_path = os.path.join(self.private_dir, "local.unitid")
if os.path.exists(unit_id_path):
with open(unit_id_path) as f:

2
jms

@ -188,7 +188,7 @@ if __name__ == '__main__':
)
parser.add_argument(
"services", type=str, default='all', nargs="*",
choices=("all", "web", "task", "receptor"),
choices=("all", "web", "task"),
help="The service to start",
)
parser.add_argument('-d', '--daemon', nargs="?", const=True)

Loading…
Cancel
Save