An application creates a lot of definitions in /etc/services. To keep services file handy with all these definitions is good practice so that we can just pipe them into /etc/services like this:
cp /etc/services /etc/services.stock
cat /path/to/build/services >> /etc/services
It works, but it's not idempotent i.e. running these commands repeatedly will cause the services file to get appended with the info again.
As I work through our Ansible playbooks, I'm trying to figure out how to do this. I could so something like this:
- command: "cat /path/to/build/services >> /etc/services"
but I don't want it to run every time I run the playbook.
Another option is to do something like this:
- name: add services
  lineinfile: 
    state: present
    insertafter: EOF
    dest: /etc/services
    line: "{{ item }}"
  with_items:
   - line 1
   - line 2
   - line 3
   - line 4
   - ...
It's not that fast, as it does each line individually.
Is there any other way around? Templates are not of that much help.
can anyone help me with this?
Thanks.