Adding Multiple Lines to a File using Ansible

Photo by Pixabay on Pexels.com

The Ansible module lineinfile will search a file for a line and ensure that it is present or absent. It is useful when you want to change a single line in a file only. But how to add multiple lines to a file? You can use a loop to do this together with lineinfile like the following:

- name: ASE Deps | Configure sudoers
  lineinfile:
    dest: /etc/sudoers
    line: "{{ item }}"
  with_items:
    - "Defaults:sybase !requiretty"
    - "sybase ALL=(ALL) NOPASSWD: /bin/mount, /bin/umount, /bin/mkdir, /bin/rmdir, /bin/ps"

Want to buy me a coffee? Do it here: https://www.buymeacoffee.com/j3rrywan9

One thought on “Adding Multiple Lines to a File using Ansible

Leave a comment