aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tasks/strategy_lineinfile.yml
blob: 2b2d02ac44b1b2900beb7c8cadb7a6a9c12f5d73 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
---
- name: Check target file for removal
  ansible.builtin.stat:
    path: "{{ _target_path }}"
  delegate_to: "{{ prometheus_target_host }}"
  become: true
  register: _target_file
  when: _target_state == "absent"

- name: Deploy target via lineinfile
  ansible.builtin.lineinfile:
    path: "{{ _target_path }}"
    line: "{{ prometheus_target_strategy_lineinfile_prefix ~ _target_host ~ prometheus_target_strategy_lineinfile_suffix }}"
    state: "{{ _target_state }}"
  delegate_to: "{{ prometheus_target_host }}"
  become: true
  register: _lineinfile_result
  when: _target_state == "present" or _target_file.stat.exists

- name: Track changes
  ansible.builtin.set_fact:
    changed: >-
      {{ changed | default(false) or (_lineinfile_result.changed | default(false)) }}