diff options
| author | Colin Wilk <colin@wilk.cx> | 2026-08-11 00:54:41 +0200 |
|---|---|---|
| committer | Colin Wilk <colin@wilk.cx> | 2026-08-11 00:54:41 +0200 |
| commit | c267536ecfbcf37e68226ade2ed29c3b1f356a98 (patch) | |
| tree | 0fb9728b0095dd34b873fa6c137b75c60734940d /tasks/strategy_lineinfile.yml | |
| parent | c33948c219032977779a7ef6d82c16e84f37b81a (diff) | |
| download | ansible-role-prometheus-target-c267536ecfbcf37e68226ade2ed29c3b1f356a98.tar.gz ansible-role-prometheus-target-c267536ecfbcf37e68226ade2ed29c3b1f356a98.zip | |
Add `state` option for removing exporters
Diffstat (limited to 'tasks/strategy_lineinfile.yml')
| -rw-r--r-- | tasks/strategy_lineinfile.yml | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tasks/strategy_lineinfile.yml b/tasks/strategy_lineinfile.yml index 7656602..2b2d02a 100644 --- a/tasks/strategy_lineinfile.yml +++ b/tasks/strategy_lineinfile.yml @@ -1,13 +1,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: present + 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 }}" + changed: >- + {{ changed | default(false) or (_lineinfile_result.changed | default(false)) }} |