我想从 vars_prompt 获取用户输入,例如:-
Enter names:- apple orange
并使用此输出在服务器上创建一个新文件:-
apple
orange
我如何使用 lineinfile 或 blockinfile 模块来实现这一点?
我想从 vars_prompt 获取用户输入,例如:-
Enter names:- apple orange
并使用此输出在服务器上创建一个新文件:-
apple
orange
我如何使用 lineinfile 或 blockinfile 模块来实现这一点?
下面的剧本与输入Enter names:- apple orange
- hosts: localhost
vars_prompt:
- name: fruits
prompt: "Enter names"
private: no
tasks:
- file:
path: /tmp/fruits
state: absent
- lineinfile:
path: /tmp/fruits
create: yes
line: "{{ item }}"
loop: "{{ fruits.split(' ') }}"
给
$ cat /tmp/fruits
apple
orange