正在从stderr_lines中提取特定值



这是我的ansible脚本

- name: show1
debug:
msg: "{{response.stderr_lines}}"

这是输出

msg:
- Using endpoint [https://us-central1-aiplatform.googleapis.com/]
- CustomJob [projects/123456/locations/us-central1/customJobs/112233445566] is submitted successfully.
- ''
- Your job is still active. You may view the status of your job with the command
- ''
- '  $ gcloud ai custom-jobs describe projects/123456/locations/us-central1/customJobs/112233445566'
- ''
- or continue streaming the logs with the command
- ''
- '  $ gcloud ai custom-jobs stream-logs projects/123456/locations/us-central1/customJobs/112233445566'

在这里,我想提取自定义作业ID,它是11122334455566

我使用了下面的选择模块

- name: show
debug:
msg: "{{train_custom_image_unmanaged_response.stderr_lines | select('search', 'describe') | list }}"

它给了我这个输出

msg:
- '  $ gcloud ai custom-jobs describe projects/123456/locations/us-central1/customJobs/112233445566'

但我只想要上面指定的工作id。你知道吗?

谢谢。

您选择了感兴趣的行。现在,您想从中分离出作业id号。您可以使用这样的正则表达式:

- set_fact:
line: "{{train_custom_image_unmanaged_response.stderr_lines | select('search', 'describe') | list }}"
- debug:
msg: "{{ line | regex_search('.*/customJobs/(\d+)', '\1') }}"

这将为您提供/customJobs/之后行末尾的所有数字。看见https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#searching-带有正则表达式的字符串

相关内容

  • 没有找到相关文章

最新更新