相关疑难解决方法(0)

在 Ansible 的 vars_prompt 中使用变量作为默认值

我试图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中可以实现吗?

ansible

5
推荐指数
1
解决办法
8257
查看次数

标签 统计

ansible ×1