-1

I want to take a user input from vars_prompt like:-

Enter names:- apple orange

and make a new file on a server with this output:-

apple
orange

how can i achieve this using lineinfile or blockinfile modules?

rocknrollaki
  • 75
  • 1
  • 4
  • 11

1 Answers1

0

The playbook below with the input 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(' ') }}"

gives

$ cat /tmp/fruits 
apple
orange
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63