feat: 作业支持增加参数和执行路径超时时间等

pull/9094/head
Aaron3S 2022-11-16 21:06:14 +08:00
parent ec462e09e0
commit 43fee40c46
11 changed files with 184 additions and 65 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ed394901fe9f21307ca1590cb77df861fef9d68f1f2d45bf21b495fb9b56e596
oid sha256:adfa9c01178d5f6490e616f62d41c71974d42f9e3bd078fcf1b3c7124384df0b
size 117024

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-15 20:31+0800\n"
"POT-Creation-Date: 2022-11-16 20:11+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -30,7 +30,7 @@ msgstr "Acls"
#: assets/models/label.py:17 assets/models/platform.py:21
#: assets/models/platform.py:72 assets/serializers/asset/common.py:86
#: assets/serializers/platform.py:138 ops/mixin.py:20 ops/models/adhoc.py:24
#: ops/models/celery.py:15 ops/models/job.py:33 ops/models/playbook.py:13
#: ops/models/celery.py:15 ops/models/job.py:34 ops/models/playbook.py:13
#: orgs/models.py:70 perms/models/asset_permission.py:51 rbac/models/role.py:29
#: settings/models.py:33 settings/serializers/sms.py:6
#: terminal/models/applet/applet.py:20 terminal/models/component/endpoint.py:11
@ -98,9 +98,10 @@ msgstr "ログイン確認"
#: acls/serializers/login_acl.py:21 assets/models/cmd_filter.py:28
#: assets/models/label.py:15 audits/models.py:29 audits/models.py:48
#: audits/models.py:79 authentication/models/connection_token.py:22
#: authentication/models/sso_token.py:15 perms/models/asset_permission.py:53
#: perms/models/perm_token.py:12 rbac/builtin.py:120
#: rbac/models/rolebinding.py:41 terminal/backends/command/models.py:20
#: authentication/models/sso_token.py:15 perms/api/user_permission/mixin.py:80
#: perms/models/asset_permission.py:53 perms/models/perm_token.py:12
#: rbac/builtin.py:120 rbac/models/rolebinding.py:41
#: terminal/backends/command/models.py:20
#: terminal/backends/command/serializers.py:13
#: terminal/models/session/session.py:30 terminal/models/session/sharing.py:33
#: terminal/notifications.py:91 terminal/notifications.py:139
@ -250,7 +251,7 @@ msgstr "アプリケーション"
#: applications/models.py:12 assets/models/label.py:20
#: assets/models/platform.py:73 assets/serializers/asset/common.py:62
#: assets/serializers/cagegory.py:8 assets/serializers/platform.py:99
#: assets/serializers/platform.py:139 perms/serializers/user_permission.py:24
#: assets/serializers/platform.py:139 perms/serializers/user_permission.py:23
#: tickets/models/ticket/apply_application.py:14
#: xpack/plugins/change_auth_plan/models/app.py:24
msgid "Category"
@ -260,8 +261,8 @@ msgstr "カテゴリ"
#: assets/models/automations/base.py:20 assets/models/cmd_filter.py:74
#: assets/models/platform.py:74 assets/serializers/asset/common.py:63
#: assets/serializers/automations/base.py:40 assets/serializers/platform.py:98
#: audits/serializers.py:40 ops/models/job.py:39
#: perms/serializers/user_permission.py:25 terminal/models/applet/applet.py:24
#: audits/serializers.py:40 ops/models/job.py:42
#: perms/serializers/user_permission.py:24 terminal/models/applet/applet.py:24
#: terminal/models/component/storage.py:57
#: terminal/models/component/storage.py:142 terminal/serializers/applet.py:33
#: tickets/models/comment.py:26 tickets/models/flow.py:57
@ -517,7 +518,7 @@ msgstr "SSHパブリックキー"
#: assets/models/_user.py:41 assets/models/automations/base.py:92
#: assets/models/domain.py:26 assets/models/gathered_user.py:19
#: assets/models/group.py:22 common/db/models.py:76 common/mixins/models.py:50
#: ops/models/base.py:54 ops/models/job.py:62 orgs/models.py:73
#: ops/models/base.py:54 ops/models/job.py:69 orgs/models.py:73
#: perms/models/asset_permission.py:75 users/models/group.py:18
#: users/models/user.py:927
msgid "Date created"
@ -556,7 +557,7 @@ msgstr "オートプッシュ"
msgid "Sudo"
msgstr "すど"
#: assets/models/_user.py:51 ops/models/adhoc.py:20 ops/models/job.py:29
#: assets/models/_user.py:51 ops/models/adhoc.py:20 ops/models/job.py:30
msgid "Shell"
msgstr "シェル"
@ -754,7 +755,7 @@ msgstr "アカウント"
#: assets/models/automations/base.py:19
#: assets/serializers/automations/base.py:20 assets/serializers/domain.py:29
#: ops/models/base.py:17 ops/models/job.py:41
#: ops/models/base.py:17 ops/models/job.py:44
#: terminal/templates/terminal/_msg_command_execute_alert.html:16
#: xpack/plugins/change_auth_plan/models/asset.py:40
msgid "Assets"
@ -767,7 +768,7 @@ msgid "Automation task"
msgstr "自動管理"
#: assets/models/automations/base.py:91 audits/models.py:115
#: audits/serializers.py:41 ops/models/base.py:49 ops/models/job.py:57
#: audits/serializers.py:41 ops/models/base.py:49 ops/models/job.py:64
#: terminal/models/applet/applet.py:60 terminal/models/applet/host.py:104
#: terminal/models/component/status.py:27 terminal/serializers/applet.py:22
#: tickets/models/ticket/general.py:281 tickets/serializers/ticket/ticket.py:19
@ -777,7 +778,7 @@ msgstr "ステータス"
#: assets/models/automations/base.py:93 assets/models/backup.py:76
#: audits/models.py:40 ops/models/base.py:55 ops/models/celery.py:59
#: ops/models/job.py:63 perms/models/asset_permission.py:69
#: ops/models/job.py:70 perms/models/asset_permission.py:69
#: terminal/models/applet/host.py:105 terminal/models/session/session.py:43
#: tickets/models/ticket/apply_application.py:28
#: tickets/models/ticket/apply_asset.py:19
@ -789,7 +790,7 @@ msgstr "開始日"
#: assets/models/automations/base.py:94
#: assets/models/automations/change_secret.py:59 ops/models/base.py:56
#: ops/models/celery.py:60 ops/models/job.py:64
#: ops/models/celery.py:60 ops/models/job.py:71
#: terminal/models/applet/host.py:106
msgid "Date finished"
msgstr "終了日"
@ -1323,7 +1324,7 @@ msgid "Currently only mail sending is supported"
msgstr "現在、メール送信のみがサポートされています"
#: assets/serializers/asset/common.py:68 assets/serializers/platform.py:101
#: xpack/plugins/cloud/models.py:109
#: perms/serializers/user_permission.py:22 xpack/plugins/cloud/models.py:109
msgid "Protocols"
msgstr "プロトコル"
@ -3071,7 +3072,7 @@ msgstr "{} から {} までの範囲"
msgid "Require periodic or regularly perform setting"
msgstr "定期的または定期的に設定を行う必要があります"
#: ops/models/adhoc.py:21 ops/models/job.py:30
#: ops/models/adhoc.py:21 ops/models/job.py:31
#, fuzzy
#| msgid "PowerShell"
msgid "Powershell"
@ -3081,22 +3082,22 @@ msgstr "PowerShell"
msgid "Pattern"
msgstr "パターン"
#: ops/models/adhoc.py:27 ops/models/job.py:37
#: ops/models/adhoc.py:27 ops/models/job.py:38
msgid "Module"
msgstr ""
#: ops/models/adhoc.py:28 ops/models/celery.py:54 ops/models/job.py:35
#: ops/models/adhoc.py:28 ops/models/celery.py:54 ops/models/job.py:36
#: terminal/models/component/task.py:17
msgid "Args"
msgstr "アルグ"
#: ops/models/adhoc.py:29 ops/models/base.py:16 ops/models/base.py:53
#: ops/models/job.py:40 ops/models/job.py:61
#: ops/models/job.py:43 ops/models/job.py:68
#: terminal/models/session/sharing.py:24
msgid "Creator"
msgstr "作成者"
#: ops/models/adhoc.py:50 ops/models/job.py:20
#: ops/models/adhoc.py:50 ops/models/job.py:21
msgid "Adhoc"
msgstr ""
@ -3122,11 +3123,11 @@ msgstr "コマンド実行"
msgid "Date last run"
msgstr "最終同期日"
#: ops/models/base.py:51 ops/models/job.py:59 xpack/plugins/cloud/models.py:169
#: ops/models/base.py:51 ops/models/job.py:66 xpack/plugins/cloud/models.py:169
msgid "Result"
msgstr "結果"
#: ops/models/base.py:52 ops/models/job.py:60
#: ops/models/base.py:52 ops/models/job.py:67
msgid "Summary"
msgstr ""
@ -3151,32 +3152,46 @@ msgstr "終了"
msgid "Date published"
msgstr "終了日"
#: ops/models/job.py:21 ops/models/job.py:38
#: ops/models/job.py:22 ops/models/job.py:41
msgid "Playbook"
msgstr ""
#: ops/models/job.py:24
#: ops/models/job.py:25
msgid "Privileged Only"
msgstr ""
#: ops/models/job.py:25
#: ops/models/job.py:26
msgid "Privileged First"
msgstr ""
#: ops/models/job.py:26
#: ops/models/job.py:27
msgid "Skip"
msgstr ""
#: ops/models/job.py:42
#: ops/models/job.py:39
msgid "Chdir"
msgstr ""
#: ops/models/job.py:40
msgid "Timeout (Seconds)"
msgstr ""
#: ops/models/job.py:45
msgid "Runas"
msgstr ""
#: ops/models/job.py:44
#: ops/models/job.py:47
#, fuzzy
#| msgid "Account key"
msgid "Runas policy"
msgstr "アカウントキー"
#: ops/models/job.py:48
#, fuzzy
#| msgid "Disable"
msgid "Variables"
msgstr "無効化"
#: ops/models/playbook.py:15
msgid "Owner"
msgstr ""
@ -3339,11 +3354,11 @@ msgstr "リンクのコピー"
msgid "Paste"
msgstr ""
#: perms/const.py:26
#: perms/const.py:27
msgid "Transfer"
msgstr ""
#: perms/const.py:27
#: perms/const.py:28
#, fuzzy
#| msgid "Clipboard copy"
msgid "Clipboard"

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:37b75571d3f4b3da6cfb5edad89bbebcd041e2b59b7c2d5642adb571116a68b1
size 103936
oid sha256:eeaa813f4ea052a1cd85b8ae5addfde6b088fd21a0261f8724d62823835512a2
size 104043

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: JumpServer 0.3.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-15 20:31+0800\n"
"POT-Creation-Date: 2022-11-16 20:11+0800\n"
"PO-Revision-Date: 2021-05-20 10:54+0800\n"
"Last-Translator: ibuler <ibuler@qq.com>\n"
"Language-Team: JumpServer team<ibuler@qq.com>\n"
@ -29,7 +29,7 @@ msgstr "访问控制"
#: assets/models/label.py:17 assets/models/platform.py:21
#: assets/models/platform.py:72 assets/serializers/asset/common.py:86
#: assets/serializers/platform.py:138 ops/mixin.py:20 ops/models/adhoc.py:24
#: ops/models/celery.py:15 ops/models/job.py:33 ops/models/playbook.py:13
#: ops/models/celery.py:15 ops/models/job.py:34 ops/models/playbook.py:13
#: orgs/models.py:70 perms/models/asset_permission.py:51 rbac/models/role.py:29
#: settings/models.py:33 settings/serializers/sms.py:6
#: terminal/models/applet/applet.py:20 terminal/models/component/endpoint.py:11
@ -97,9 +97,10 @@ msgstr "登录复核"
#: acls/serializers/login_acl.py:21 assets/models/cmd_filter.py:28
#: assets/models/label.py:15 audits/models.py:29 audits/models.py:48
#: audits/models.py:79 authentication/models/connection_token.py:22
#: authentication/models/sso_token.py:15 perms/models/asset_permission.py:53
#: perms/models/perm_token.py:12 rbac/builtin.py:120
#: rbac/models/rolebinding.py:41 terminal/backends/command/models.py:20
#: authentication/models/sso_token.py:15 perms/api/user_permission/mixin.py:80
#: perms/models/asset_permission.py:53 perms/models/perm_token.py:12
#: rbac/builtin.py:120 rbac/models/rolebinding.py:41
#: terminal/backends/command/models.py:20
#: terminal/backends/command/serializers.py:13
#: terminal/models/session/session.py:30 terminal/models/session/sharing.py:33
#: terminal/notifications.py:91 terminal/notifications.py:139
@ -245,7 +246,7 @@ msgstr "应用管理"
#: applications/models.py:12 assets/models/label.py:20
#: assets/models/platform.py:73 assets/serializers/asset/common.py:62
#: assets/serializers/cagegory.py:8 assets/serializers/platform.py:99
#: assets/serializers/platform.py:139 perms/serializers/user_permission.py:24
#: assets/serializers/platform.py:139 perms/serializers/user_permission.py:23
#: tickets/models/ticket/apply_application.py:14
#: xpack/plugins/change_auth_plan/models/app.py:24
msgid "Category"
@ -255,8 +256,8 @@ msgstr "类别"
#: assets/models/automations/base.py:20 assets/models/cmd_filter.py:74
#: assets/models/platform.py:74 assets/serializers/asset/common.py:63
#: assets/serializers/automations/base.py:40 assets/serializers/platform.py:98
#: audits/serializers.py:40 ops/models/job.py:39
#: perms/serializers/user_permission.py:25 terminal/models/applet/applet.py:24
#: audits/serializers.py:40 ops/models/job.py:42
#: perms/serializers/user_permission.py:24 terminal/models/applet/applet.py:24
#: terminal/models/component/storage.py:57
#: terminal/models/component/storage.py:142 terminal/serializers/applet.py:33
#: tickets/models/comment.py:26 tickets/models/flow.py:57
@ -492,7 +493,7 @@ msgstr "SSH 公钥"
#: assets/models/_user.py:41 assets/models/automations/base.py:92
#: assets/models/domain.py:26 assets/models/gathered_user.py:19
#: assets/models/group.py:22 common/db/models.py:76 common/mixins/models.py:50
#: ops/models/base.py:54 ops/models/job.py:62 orgs/models.py:73
#: ops/models/base.py:54 ops/models/job.py:69 orgs/models.py:73
#: perms/models/asset_permission.py:75 users/models/group.py:18
#: users/models/user.py:927
msgid "Date created"
@ -531,7 +532,7 @@ msgstr "自动推送"
msgid "Sudo"
msgstr "Sudo"
#: assets/models/_user.py:51 ops/models/adhoc.py:20 ops/models/job.py:29
#: assets/models/_user.py:51 ops/models/adhoc.py:20 ops/models/job.py:30
msgid "Shell"
msgstr "Shell"
@ -719,7 +720,7 @@ msgstr "账号管理"
#: assets/models/automations/base.py:19
#: assets/serializers/automations/base.py:20 assets/serializers/domain.py:29
#: ops/models/base.py:17 ops/models/job.py:41
#: ops/models/base.py:17 ops/models/job.py:44
#: terminal/templates/terminal/_msg_command_execute_alert.html:16
#: xpack/plugins/change_auth_plan/models/asset.py:40
msgid "Assets"
@ -730,7 +731,7 @@ msgid "Automation task"
msgstr "自动化任务"
#: assets/models/automations/base.py:91 audits/models.py:115
#: audits/serializers.py:41 ops/models/base.py:49 ops/models/job.py:57
#: audits/serializers.py:41 ops/models/base.py:49 ops/models/job.py:64
#: terminal/models/applet/applet.py:60 terminal/models/applet/host.py:104
#: terminal/models/component/status.py:27 terminal/serializers/applet.py:22
#: tickets/models/ticket/general.py:281 tickets/serializers/ticket/ticket.py:19
@ -740,7 +741,7 @@ msgstr "状态"
#: assets/models/automations/base.py:93 assets/models/backup.py:76
#: audits/models.py:40 ops/models/base.py:55 ops/models/celery.py:59
#: ops/models/job.py:63 perms/models/asset_permission.py:69
#: ops/models/job.py:70 perms/models/asset_permission.py:69
#: terminal/models/applet/host.py:105 terminal/models/session/session.py:43
#: tickets/models/ticket/apply_application.py:28
#: tickets/models/ticket/apply_asset.py:19
@ -752,7 +753,7 @@ msgstr "开始日期"
#: assets/models/automations/base.py:94
#: assets/models/automations/change_secret.py:59 ops/models/base.py:56
#: ops/models/celery.py:60 ops/models/job.py:64
#: ops/models/celery.py:60 ops/models/job.py:71
#: terminal/models/applet/host.py:106
msgid "Date finished"
msgstr "结束日期"
@ -1226,7 +1227,7 @@ msgid "Currently only mail sending is supported"
msgstr "当前只支持邮件发送"
#: assets/serializers/asset/common.py:68 assets/serializers/platform.py:101
#: xpack/plugins/cloud/models.py:109
#: perms/serializers/user_permission.py:22 xpack/plugins/cloud/models.py:109
msgid "Protocols"
msgstr "协议组"
@ -2898,7 +2899,7 @@ msgstr "输入在 {} - {} 范围之间"
msgid "Require periodic or regularly perform setting"
msgstr "需要周期或定期设置"
#: ops/models/adhoc.py:21 ops/models/job.py:30
#: ops/models/adhoc.py:21 ops/models/job.py:31
#, fuzzy
#| msgid "PowerShell"
msgid "Powershell"
@ -2908,22 +2909,22 @@ msgstr "PowerShell"
msgid "Pattern"
msgstr "模式"
#: ops/models/adhoc.py:27 ops/models/job.py:37
#: ops/models/adhoc.py:27 ops/models/job.py:38
msgid "Module"
msgstr ""
#: ops/models/adhoc.py:28 ops/models/celery.py:54 ops/models/job.py:35
#: ops/models/adhoc.py:28 ops/models/celery.py:54 ops/models/job.py:36
#: terminal/models/component/task.py:17
msgid "Args"
msgstr "参数"
#: ops/models/adhoc.py:29 ops/models/base.py:16 ops/models/base.py:53
#: ops/models/job.py:40 ops/models/job.py:61
#: ops/models/job.py:43 ops/models/job.py:68
#: terminal/models/session/sharing.py:24
msgid "Creator"
msgstr "创建者"
#: ops/models/adhoc.py:50 ops/models/job.py:20
#: ops/models/adhoc.py:50 ops/models/job.py:21
msgid "Adhoc"
msgstr ""
@ -2943,11 +2944,11 @@ msgstr "最后执行"
msgid "Date last run"
msgstr "最后执行日期"
#: ops/models/base.py:51 ops/models/job.py:59 xpack/plugins/cloud/models.py:169
#: ops/models/base.py:51 ops/models/job.py:66 xpack/plugins/cloud/models.py:169
msgid "Result"
msgstr "结果"
#: ops/models/base.py:52 ops/models/job.py:60
#: ops/models/base.py:52 ops/models/job.py:67
msgid "Summary"
msgstr "汇总"
@ -2970,36 +2971,50 @@ msgstr "结束"
msgid "Date published"
msgstr "发布日期"
#: ops/models/job.py:21 ops/models/job.py:38
#: ops/models/job.py:22 ops/models/job.py:41
msgid "Playbook"
msgstr "Playbook"
#: ops/models/job.py:24
#: ops/models/job.py:25
#, fuzzy
#| msgid "Privileged"
msgid "Privileged Only"
msgstr "特权账号"
#: ops/models/job.py:25
#: ops/models/job.py:26
#, fuzzy
#| msgid "Privileged"
msgid "Privileged First"
msgstr "特权账号"
#: ops/models/job.py:26
#: ops/models/job.py:27
msgid "Skip"
msgstr ""
#: ops/models/job.py:42
#: ops/models/job.py:39
msgid "Chdir"
msgstr "执行路径"
#: ops/models/job.py:40
msgid "Timeout (Seconds)"
msgstr "超时时间(秒)"
#: ops/models/job.py:45
msgid "Runas"
msgstr ""
#: ops/models/job.py:44
#: ops/models/job.py:47
#, fuzzy
#| msgid "Account policy"
msgid "Runas policy"
msgstr "账号策略"
#: ops/models/job.py:48
#, fuzzy
#| msgid "Disable"
msgid "Variables"
msgstr "禁用"
#: ops/models/playbook.py:15
msgid "Owner"
msgstr "Owner"
@ -3151,11 +3166,11 @@ msgstr "复制链接"
msgid "Paste"
msgstr ""
#: perms/const.py:26
#: perms/const.py:27
msgid "Transfer"
msgstr ""
#: perms/const.py:27
#: perms/const.py:28
#, fuzzy
#| msgid "Clipboard copy"
msgid "Clipboard"

View File

@ -5,6 +5,7 @@ class DefaultCallback:
STATUS_MAPPER = {
'successful': 'success',
'failure': 'failed',
'failed': 'failed',
'running': 'running',
'pending': 'pending',
'unknown': 'unknown'

View File

@ -13,7 +13,7 @@ class AdHocRunner:
"reboot", 'shutdown', 'poweroff', 'halt', 'dd', 'half', 'top'
]
def __init__(self, inventory, module, module_args='', pattern='*', project_dir='/tmp/'):
def __init__(self, inventory, module, module_args='', pattern='*', project_dir='/tmp/', extra_vars={}):
self.id = uuid.uuid4()
self.inventory = inventory
self.pattern = pattern
@ -22,6 +22,7 @@ class AdHocRunner:
self.project_dir = project_dir
self.cb = DefaultCallback()
self.runner = None
self.extra_vars = extra_vars
def check_module(self):
if self.module not in self.cmd_modules_choices:
@ -38,6 +39,7 @@ class AdHocRunner:
os.mkdir(self.project_dir, 0o755)
ansible_runner.run(
extravars=self.extra_vars,
host_pattern=self.pattern,
private_data_dir=self.project_dir,
inventory=self.inventory,

View File

@ -0,0 +1,42 @@
# Generated by Django 3.2.14 on 2022-11-16 10:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ops', '0029_auto_20221111_1919'),
]
operations = [
migrations.AlterModelOptions(
name='celerytask',
options={'ordering': ('name',)},
),
migrations.AddField(
model_name='job',
name='variables',
field=models.JSONField(default=dict, verbose_name='Variables'),
),
migrations.AlterField(
model_name='celerytask',
name='name',
field=models.CharField(max_length=1024, verbose_name='Name'),
),
migrations.AlterField(
model_name='celerytaskexecution',
name='date_finished',
field=models.DateTimeField(null=True, verbose_name='Date finished'),
),
migrations.AlterField(
model_name='celerytaskexecution',
name='date_published',
field=models.DateTimeField(auto_now_add=True, verbose_name='Date published'),
),
migrations.AlterField(
model_name='celerytaskexecution',
name='date_start',
field=models.DateTimeField(null=True, verbose_name='Date start'),
),
]

View File

@ -0,0 +1,28 @@
# Generated by Django 3.2.14 on 2022-11-16 12:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ops', '0030_auto_20221116_1811'),
]
operations = [
migrations.AddField(
model_name='job',
name='chdir',
field=models.CharField(blank=True, default='', max_length=1024, null=True, verbose_name='Chdir'),
),
migrations.AddField(
model_name='job',
name='comment',
field=models.CharField(blank=True, default='', max_length=1024, null=True, verbose_name='Comment'),
),
migrations.AddField(
model_name='job',
name='timeout',
field=models.IntegerField(default=60, verbose_name='Timeout (Seconds)'),
),
]

View File

@ -0,0 +1,4 @@
# 内置环境变量
BUILTIN_VARIABLES = {
}

View File

@ -1,3 +1,4 @@
import json
import os
import uuid
import logging
@ -35,6 +36,8 @@ class Job(BaseCreateUpdateModel):
args = models.CharField(max_length=1024, default='', verbose_name=_('Args'), null=True, blank=True)
module = models.CharField(max_length=128, choices=Modules.choices, default=Modules.shell,
verbose_name=_('Module'), null=True)
chdir = models.CharField(default="", max_length=1024, verbose_name=_('Chdir'), null=True, blank=True)
timeout = models.IntegerField(default=60, verbose_name=_('Timeout (Seconds)'))
playbook = models.ForeignKey('ops.Playbook', verbose_name=_("Playbook"), null=True, on_delete=models.SET_NULL)
type = models.CharField(max_length=128, choices=Types.choices, default=Types.adhoc, verbose_name=_("Type"))
owner = models.ForeignKey('users.User', verbose_name=_("Creator"), on_delete=models.SET_NULL, null=True)
@ -42,6 +45,8 @@ class Job(BaseCreateUpdateModel):
runas = models.CharField(max_length=128, default='root', verbose_name=_('Runas'))
runas_policy = models.CharField(max_length=128, choices=RunasPolicies.choices, default=RunasPolicies.skip,
verbose_name=_('Runas policy'))
variables = models.JSONField(default=dict, verbose_name=_('Variables'))
comment = models.CharField(max_length=1024, default='', verbose_name=_('Comment'), null=True, blank=True)
@property
def inventory(self):
@ -50,6 +55,9 @@ class Job(BaseCreateUpdateModel):
def create_execution(self):
return self.executions.create()
def get_variables(self):
return json.loads(self.variables)
class JobExecution(BaseCreateUpdateModel):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
@ -70,7 +78,7 @@ class JobExecution(BaseCreateUpdateModel):
if self.job.type == 'adhoc':
runner = AdHocRunner(
self.inventory_path, self.job.module, module_args=self.job.args,
pattern="all", project_dir=self.private_dir
pattern="all", project_dir=self.private_dir, extra_vars=self.job.get_variables()
)
elif self.job.type == 'playbook':
runner = PlaybookRunner(

View File

@ -14,6 +14,10 @@ class JobSerializer(serializers.ModelSerializer):
model = Job
fields = [
"id", "name", "instant", "type", "module", "args", "playbook", "assets", "runas_policy", "runas", "owner",
"variables",
"timeout",
"chdir",
"comment",
"date_created",
"date_updated"
]