You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Ansible中实现用户指定Profile的精确匹配校验?

解决Ansible Profile精确匹配失败任务的问题

要实现仅当用户输入的Profile名称与列表中某个条目完全匹配时才触发任务失败,核心是先从命令输出中提取出精确的Profile名称列表,再进行精确匹配判断,避免原字符串包含匹配导致的误触发。

修改后的Playbook示例

---
- hosts: localhost
  gather_facts: no
  become: true
  tasks: 
    - name: Getting the list of Profiles
      shell: some command to get the list of profiles
      register: output
      
    - name: Printing the list of profiles
      debug:
        msg: "{{ output.stdout_lines }}"
        
    - name: Extract exact profile names from output
      set_fact:
        existing_profiles: "{{ output.stdout_lines | select('match', '.*Profile=.*') | map('regex_replace', '.*Profile=(.*)$', '\\1') | list }}"
        
    - name: Failing the task when the specified profile already exists
      fail:
        msg: The Profile {{ userinput }} already exists
      when: userinput in
相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 04:54:35