I have many lines need to add, like
if just one dest, will be
- name: add line
  lineinfile:
    dest: "/tmp/aaa.txt"
    line: "{{ item }}"
  with_items:
    - "toady"
    - "is"
    - "a"
    - "good"
    - "day"
and then, also have many files need to add, like
if just one line, will be
- name: add line
  lineinfile:
    dest: "{{ item }}"
    line: "today"
  with_items:
    - "/tmp/aaa.txt"
    - "/tmp/bbb.txt"
    - "/tmp/ccc.txt"
Now I need mix them, both have all dest and all line, but I can't try it success.
Both of them are an array or object, I try many method still fail.
Helppppppp please :(
Thanks everyone
Use nested. For example
- hosts: localhost
  vars:
    files: [aaa.txt, bbb.txt, ccc.txt]
    lines: [today, good, day]
  tasks:
    - lineinfile:
        create: true
        dest: "/tmp/{{ item.0 }}"
        line: "{{ item.1 }}"
      with_nested:
        - "{{ files }}"
        - "{{ lines }}"
gives
shell> cat /tmp/aaa.txt 
today
good
day
shell> cat /tmp/bbb.txt 
today
good
day
shell> cat /tmp/ccc.txt 
today
good
day
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With