我试图vars_prompt
在 Ansible 中使用取自事实(或之前定义的变量)的默认值。该剧本旨在用作初始配置的临时剧本。
我的剧本:
---
- 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 }}"
Run Code Online (Sandbox Code Playgroud)
当前结果:
please enter the name for the target [{{ ansible_hostname }}]:
ERROR! 'ansible_hostname' is undefined
Run Code Online (Sandbox Code Playgroud)
预期结果(假设ansible_hostname=server01
:
please enter the name for the target [server01]:
Run Code Online (Sandbox Code Playgroud)
在Ansible中可以实现吗?
pause
这可以使用以下模块来实现:
---
- 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 }}"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8257 次 |
最近记录: |