Ansible 在使用暂停时将垃圾放入变量中

Ansible puts garbage in variable when using pause

当我尝试设置暂停以提示输入变量时(如果未设置此变量),我在变量上出现垃圾信息(无论是否触发提示)。

例如:

- pause:
  prompt: "Enter the directory of installation"
when: docroot is undefined
register: docroot

我在变量中得到它:

'{'\''skip_reason'\'': '\''Conditional result was False'\'', '\''skipped'\'': True, '\''changed'\'': False}'

即使没有触发提示。

阅读 docs for the pause module

大多数模块 return 值字典,提供有关模块 运行 时发生的情况的各种详细信息。因此,您不能简单地注册一个变量并期望它包含用户输入。试试这个:

- block:      
    - pause:
        prompt: "Enter the directory of installation"
      register: prompt_data
    - set_fact:
        docroot: "{{ prompt_data.user_input }}"
  when: docroot is undefined