我想根据 Ansible 剧本中的用户输入选择特定变量。具体来说,我想在服务器的位置上请求用户输入,然后根据输入执行特定操作。
这是当前的 ansible 剧本:
- hosts: all
remote_user: root
gather_facts: True
vars:
loc1: "10.13.1.140"
loc2: "10.13.1.141"
loc3: "10.13.1.142"
vars_prompt:
- name: location
prompt: "Location of server? Input options: loc1/loc2/loc3"
private: no
tasks:
- name: Test connectivity to user selected location
wait_for: host={{ vars.location }} port=9999 delay=0 timeout=10 state=started
[root@ansmgtpr-labc01 cfengine]# ansible-playbook testpoo.yaml -i /tmp/test
SSH password:
Location of server? Input options: loc1/loc2/loc3: loc2
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [hostname.domain.com]
TASK [Test connectivity to user selected location] *****************************
fatal: [hostname.domain.com]: FAILED! => {"changed": false, "elapsed": 10, "failed": true, "msg": "Timeout when waiting for loc2:9999"}
PLAY RECAP *********************************************************************
hostname.domain.com : ok=1 changed=0 unreachable=0 failed=1
最佳答案
您的任务正在等待 loc2
,因此消息 Timeout when waiting for loc2:9999
.
使用 host={{ vars[location] }}
反而。
比较以下任务的输出:
tasks:
- name: Show the value user entered
debug: var=vars.location
- name: Use the entered value as an index
debug: var=vars[location]
TASK [Show the value user entered] *********************************************
ok: [localhost] => {
"vars.location": "loc2"
}
TASK [Use the entered value as an index] ***************************************
ok: [localhost] => {
"vars[location]": "10.13.1.141"
}
https://stackoverflow.com/questions/41369834/
相关文章:
haskell - 如何使 Pipe 与 Haskell 的 Pipe 库并发?
compiler-construction - 这个产生式规则是否左递归?
c - 这是什么意思,我该如何纠正它 *** 检测到堆栈粉碎 *** : ./array1outpu
spring-mvc - 处理 org.thymeleaf.exceptions.TemplateI
python-3.x - 模块 'urllib' 没有属性 'request'
haskell - Machines 和 Conduits(或其他类似库)之间的概念区别是什么?