-1

我想从 vars_prompt 获取用户输入,例如:-

Enter names:- apple orange

并使用此输出在服务器上创建一个新文件:-

apple
orange

我如何使用 lineinfile 或 blockinfile 模块来实现这一点?

4

1 回答 1

0

下面的剧本与输入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
于 2019-06-25T23:18:17.630 回答