【发布时间】:2020-04-22 04:08:27
【问题描述】:
我的剧本看起来像:
---
- name: Install and configure AD authentication
hosts: test
become: yes
become_user: root
vars:
hostname: "{{ host_name }}"
vars_prompt:
- name: "bind_password"
prompt: "Password for xxx.local\\user"
private: yes
tasks:
- name: Ansible prompt example.
debug:
msg: "{{ bind_password }}"
- name: Ansible prompt example.
debug:
msg: "{{ host_name }}"
我正在使用下面的命令来传递变量 ansible-playbook hostname_set.yml --extra-vars "host_name= 'xxx.xxx.local'"
但我没有得到我用于设置主机名的确切变量值。
Password for xxx.xxx\user:
PLAY [Install and configure AD authentication]
TASK [Gathering Facts]
ok: [x.x.x.x]
TASK [Ansible prompt example.]
ok: [x.x.x.x] => {
"msg": "wel"
}
TASK [Ansible prompt example.]
ok: [x.x.x.x] => {
"msg": ""
}
TASK [Setup the hostname]
changed: [x.x.x.x]
PLAY RECAP
x.x.x.x : ok=4 changed=1 unreachable=0 failed=0
skipped=0 rescued=0 ignored=0
【问题讨论】:
-
请不要粘贴图像以显示命令输出。而是将输出粘贴到代码块中。这更容易阅读(至少对我的老眼睛来说),如果需要可以复制粘贴,并且可以被 SO 内部或外部搜索引擎索引。请注意,在这种特定情况下,您的 MCVE 可能已简化为单个命令行:
ansible localhost -e "host_name= 'xxx.xxx.local'" -m debug -a msg="{{host_name}}"(它返回与上述相同的结果,并且在删除多余的空间时会返回预期结果)。