代码之家  ›  专栏  ›  技术社区  ›  skr

如何在ansible playbook中运行每个任务之前提示用户“是/否”?[副本]

  •  0
  • skr  · 技术社区  · 6 年前

    我试着用 vars_prompt 在Ansible中,默认值取自事实(或先前定义的变量)。playbook将用作初始资源调配的临时脚本。

    ---
    - hosts: server01
      gather_facts: True
      vars_prompt:
        - name: new_hostname
          prompt: please enter the name for the target
          default: "{{ ansible_hostname }}"
          private: no
      tasks:
        - debug: msg="{{ new_hostname }}"
    

    当前结果:

    please enter the name for the target [{{ ansible_hostname }}]:
    ERROR! 'ansible_hostname' is undefined
    

    ansible_hostname=server01 :

    please enter the name for the target [server01]:
    

    0 回复  |  直到 8 年前
        1
  •  3
  •   techraf    7 年前

    这可以使用 pause module

    ---
    - hosts: server01
      gather_facts: True
      tasks:
        - pause:
            prompt: please enter the name for the target [{{ ansible_hostname }}]
          register: prompt
    
        - debug:
            msg: "{{ prompt.user_input if prompt.user_input else ansible_hostname }}"