neuro_ansible/yaml_sub/myrepo_clean.yaml

29 lines
656 B
YAML
Raw Permalink Normal View History

2024-03-29 01:55:48 +01:00
---
- name: Find files everything except myrepo.repo
2024-04-04 13:54:30 +02:00
ansible.builtin.find:
2024-03-29 01:55:48 +01:00
paths: /etc/yum.repos.d
file_type: file
excludes: "myrepo.repo"
register: output
2024-04-04 13:54:30 +02:00
2024-03-29 01:55:48 +01:00
- name: Delete other files
2024-04-04 13:54:30 +02:00
ansible.builtin.file:
2024-03-29 01:55:48 +01:00
path: "{{ item.path }}"
state: absent
loop: "{{ output.files }}"
- name: Check for marker line
2024-04-04 13:54:30 +02:00
ansible.builtin.lineinfile:
2024-03-29 01:55:48 +01:00
path: /etc/yum.repos.d/myrepo.repo
create: true
state: present
line: "# BEGIN ANSIBLE MANAGED BLOCK"
register: marker_check
- name: Delete file if marker is absent
2024-04-04 13:54:30 +02:00
ansible.builtin.file:
2024-03-29 01:55:48 +01:00
path: /etc/yum.repos.d/myrepo.repo
state: absent
when: marker_check.changed