Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] 快捷命令执行报错 #10185

Closed
Anorpi opened this issue Apr 12, 2023 · 11 comments
Closed

[Bug] 快捷命令执行报错 #10185

Anorpi opened this issue Apr 12, 2023 · 11 comments
Assignees
Labels
🐛 Bug Something isn't working | 缺陷

Comments

@Anorpi
Copy link

Anorpi commented Apr 12, 2023

JumpServer 版本( v2.28 之前的版本不再支持 )
JumpServer v3.1.2

浏览器版本
Chrome 版本 111.0.5563.147(正式版本) (64 位)

Bug 描述
我是通过 jmsctl.sh upgrade 命令将 v2.28 升级到 v3.1.2的。但使用 快捷命令功能时,总是遇到
“Start adhoc execution error: 'set' object is not subscriptable” 报错。

Bug 重现步骤(有截图更好)
1.进入 “快捷命令”
2.左侧选择一个主机
3.右侧输入 w 命令,点击执行

w

@Anorpi Anorpi added the 🐛 Bug Something isn't working | 缺陷 label Apr 12, 2023
@github-actions github-actions bot added the 🔔 Pending processing Awaiting processing from the issue assignees | 待处理 label Apr 12, 2023
@BaiJiangJie
Copy link
Member

BaiJiangJie commented Apr 12, 2023

测试了几次没有复现,看下后端 celery_ansible.log 的日志报错信息。

@github-actions github-actions bot added ⏳ Pending feedback Awaiting feedback from the issue reporter | 待反馈 and removed 🔔 Pending processing Awaiting processing from the issue assignees | 待处理 labels Apr 12, 2023
@Anorpi
Copy link
Author

Anorpi commented Apr 12, 2023

看下后端 celery_ansible.log 的日志报错信息

ww

@github-actions github-actions bot added 🔔 Pending processing Awaiting processing from the issue assignees | 待处理 and removed ⏳ Pending feedback Awaiting feedback from the issue reporter | 待反馈 labels Apr 12, 2023
@BaiJiangJie
Copy link
Member

BaiJiangJie commented Apr 12, 2023

日志里没有打堆栈信息还看不出来,怎么复现一下呢?

@github-actions github-actions bot added ⏳ Pending feedback Awaiting feedback from the issue reporter | 待反馈 and removed 🔔 Pending processing Awaiting processing from the issue assignees | 待处理 labels Apr 12, 2023
@BaiJiangJie
Copy link
Member

BaiJiangJie commented Apr 12, 2023

按照下面的方法修改一下代码,来看看日志输出信息:

# 进入 celery 容器
docker exec -it jms_celery bash

# 编辑文件,修改代码
vi apps/ops/tasks.py

# 修改第 50 行代码

(修改前)logger.error("Start adhoc execution error: {}".format(e))


(修改后)logger.error("Start adhoc execution error: {}".format(e), exc_info=True)

# 退出容器
exit 

# 重启 celery 容器
docker restart jms_celery 


# 执行任务,再查看 celery_ansible.log 日志

@github-actions github-actions bot added 🔔 Pending processing Awaiting processing from the issue assignees | 待处理 and removed ⏳ Pending feedback Awaiting feedback from the issue reporter | 待反馈 labels Apr 12, 2023
@Anorpi
Copy link
Author

Anorpi commented Apr 12, 2023

按照下面的方法修改一下代码,来看看日志输出信息:

# 进入 celery 容器
docker exec -it jms_celery bash

# 编辑文件,修改代码
vi apps/ops/tasks.py

# 修改第 50 行代码

(修改前)logger.error("Start adhoc execution error: {}".format(e))


(修改后)logger.error("Start adhoc execution error: {}".format(e), exc_info=True)

# 退出容器
exit 

# 重启 celery 容器
docker restart jms_celery 


# 执行任务,再查看 celery_ansible.log 日志

按照这个编写了 apps/ops/tasks.py 但好像日志格式还是没什么变化。
刚测试的时候发现,是有些机器会报这个错 有些则不会,具体看下面的截图。
最后选了另外一台主机进行执行,没有报错。

jmp1
jmp5

@BaiJiangJie
Copy link
Member

BaiJiangJie commented Apr 12, 2023

那再修改一下第 76 行,修改前的代码和第 50 行一样。

image

@github-actions github-actions bot added ⏳ Pending feedback Awaiting feedback from the issue reporter | 待反馈 and removed 🔔 Pending processing Awaiting processing from the issue assignees | 待处理 labels Apr 12, 2023
@Anorpi
Copy link
Author

Anorpi commented Apr 12, 2023

报错如下

Task ops.tasks.run_ops_job_execution[1e8849e7-70d1-4569-8b0d-bb5acca1c1ef] received
>> Set language to zh-hans
>> Set org to 00000000-0000-0000-0000-000000000002
2023-04-12 17:16:38 [tasks ERROR] Start adhoc execution error: 'set' object is not subscriptable
Traceback (most recent call last):
  File "/opt/jumpserver/apps/ops/tasks.py", line 70, in run_ops_job_execution
    execution.start()
  File "/opt/jumpserver/apps/ops/models/job.py", line 445, in start
    runner = self.get_runner()
  File "/opt/jumpserver/apps/ops/models/job.py", line 273, in get_runner
    inv.write_to_file(self.inventory_path)
  File "/opt/jumpserver/apps/ops/ansible/inventory.py", line 229, in write_to_file
    data = self.generate(path_dir)
  File "/opt/jumpserver/apps/ops/ansible/inventory.py", line 192, in generate
    account = self.select_account(asset)
  File "/opt/jumpserver/apps/ops/ansible/inventory.py", line 174, in select_account
    account_selected = accounts[0]
TypeError: 'set' object is not subscriptable
Start adhoc execution error: 'set' object is not subscriptable
Traceback (most recent call last):
  File "/opt/jumpserver/apps/ops/tasks.py", line 70, in run_ops_job_execution
    execution.start()
  File "/opt/jumpserver/apps/ops/models/job.py", line 445, in start
    runner = self.get_runner()
  File "/opt/jumpserver/apps/ops/models/job.py", line 273, in get_runner
    inv.write_to_file(self.inventory_path)
  File "/opt/jumpserver/apps/ops/ansible/inventory.py", line 229, in write_to_file
    data = self.generate(path_dir)
  File "/opt/jumpserver/apps/ops/ansible/inventory.py", line 192, in generate
    account = self.select_account(asset)
  File "/opt/jumpserver/apps/ops/ansible/inventory.py", line 174, in select_account
    account_selected = accounts[0]
TypeError: 'set' object is not subscriptable
Task ops.tasks.run_ops_job_execution[1e8849e7-70d1-4569-8b0d-bb5acca1c1ef] succeeded in 0.14671393483877182s: None

@github-actions github-actions bot added 🔔 Pending processing Awaiting processing from the issue assignees | 待处理 and removed ⏳ Pending feedback Awaiting feedback from the issue reporter | 待反馈 labels Apr 12, 2023
@BaiJiangJie
Copy link
Member

# 进入celery容器再修改一下文件 apps.ops.ansible.inventory.py
vi apps/ops/ansible/inventory.py

# 第 174 行上面添加一行

print('LOG FOR ACCOUNT: accounts: {}, type: {}'.format(accounts, type(accounts)))

# 退出容器,重启,执行任务,查看日志

image

@github-actions github-actions bot added ⏳ Pending feedback Awaiting feedback from the issue reporter | 待反馈 and removed 🔔 Pending processing Awaiting processing from the issue assignees | 待处理 labels Apr 12, 2023
@Anorpi
Copy link
Author

Anorpi commented Apr 12, 2023

大概定位到了。我快捷命令 执行用户手动输入的 root ,但当前用户没有这个资源的root账号权限 导致报错。感觉可以做个提示。

Snipaste_2023-04-12_17-46-15

@github-actions github-actions bot added 🔔 Pending processing Awaiting processing from the issue assignees | 待处理 and removed ⏳ Pending feedback Awaiting feedback from the issue reporter | 待反馈 labels Apr 12, 2023
@Anorpi
Copy link
Author

Anorpi commented Apr 12, 2023

我给用户授权root后 再执行了一次,成功了。见上面截图的最后几行信息。

@BaiJiangJie
Copy link
Member

问题原因找到了,会在 v3.1.3 和 v3.2 版本中进行修复。

@github-actions github-actions bot added ⏳ Pending feedback Awaiting feedback from the issue reporter | 待反馈 and removed 🔔 Pending processing Awaiting processing from the issue assignees | 待处理 labels Apr 12, 2023
@github-actions github-actions bot removed the ⏳ Pending feedback Awaiting feedback from the issue reporter | 待反馈 label Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working | 缺陷
Development

No branches or pull requests

3 participants