【问题标题】:--tags does not skip vars_prompt in ansible--tags 不会在 ansible 中跳过 vars_prompt
【发布时间】:2021-02-17 07:15:34
【问题描述】:

当我运行 ansible-playbook --tags tag2 时,为什么它不从 tag1 跳过 vars_prompt?无论如何,它会从 tag1 中跳过调试消息。请帮忙。这让我编写了 2 个不同的剧本。

---
 - name: variable print using var
   hosts: all
   gather_facts: no
   tags: tag1

   vars_prompt:
     - name: ask_user
       prompt: enter your name
       private: no

   tasks:
     - debug:
         msg: "{{ ask_user}} works in ABC company"

 - hosts: all
   gather_facts: no
   tags: tag2

   tasks:
     - name: normal message
       debug:
         msg: "This is 2nd tag"

【问题讨论】:

    标签: ansible


    【解决方案1】:

    问:--tags 不会跳过 Ansible 中的 vars_prompt

    答:vars_prompt 不是任务,因此不能跳过。引用自Tags

    使用标签执行或跳过选定的任务是一个两步过程:

    1. 为您的任务添加标签,可以单独添加标签,也可以使用从块、游戏、角色或导入中继承的标签。
    1. 在运行 playbook 时选择或跳过标签。

    如果您想跳过变量提示,请使用 pause 而不是 vars_prompt。例如,下面的剧本做你想做的事

    - hosts: localhost
      gather_facts: false
      tags: tag1
      tasks:
        - pause:
            prompt: Enter your name
            echo: true
          register: result
        - set_fact:
            ask_user: "{{ result.user_input }}"
        - debug:
            msg: "{{ ask_user }} works in ABC company"
    
    - hosts: localhost
      gather_facts: false
      tags: tag2
      tasks:
        - debug:
            msg: This is tag2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      相关资源
      最近更新 更多