Quick Ansible to update a file

Engineering Mar 11, 2020

Self reference.
Use case was to update a configfile (datadog) in all currently running instances..And restart the process.

- hosts: all
  tasks:
    - name: line insert
      lineinfile:
        path: /etc/datadog-agent/datadog.yaml
        insertafter: 'collect_ec2_tags: false'
        line: 'collect_ec2_tags: true'
      notify:
        - restarting
      become: true
  handlers:
    - name: restarting
      service:
        name: datadog-agent
        state: restarted
      become: true

hosts file:

[all]
192.x.x.x
192.x.x.x

Srujan

You should go to about section on this site.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.