- name: testplay
hosts: localhost
gather_facts: false
vars_prompt:
- name: register_name
prompt: "Enter your register name in a listformat to pick one by one"
private: no
- name: node_list
prompt: "Enter your register names in list like
same,charles,william,george"
private: no
with_items: "{{ register_name }}"
tasks:
- debug:
msg: "display all {{ register_names }} here"
- name: write register names to a file one below the other
shell: echo '{{ item }}' >> file.txt
with_items: "{{ register_name }}"
我想在提示模块的列表中输入值,以便逐个选择,不确定此处的循环如何工作,请建议(我尝试了with_item/loop,但没有工作)
# ansible-playbook test.yml
Enter register_no in a listformat to pick one by one: same,charles,william,george
1条答案
按热度按时间0h4hbjxa1#
vars_prompt
接受文本。没有办法从头开始输入列表。但使用split
很容易实现(添加trim
以确保安全)。简而言之,下面是prompt_demo.yml
剧本:给出: