--- - name: update metricbeat hosts: linux tasks: - name: define elasticsearch hosts become: true lineinfile: path: /etc/metricbeat/metricbeat.yml regexp: 'hosts: \["localhost:9200"\]' #insertafter: 'hosts: \["localhost:9200"\]' line: ' hosts: ["dm-nagios.local:9200"]' state: present backrefs: yes