neuro_ansible/yaml_sub/myrepo_clean.yaml
2024-04-04 13:54:30 +02:00

28 lines
656 B
YAML

---
- name: Find files everything except myrepo.repo
ansible.builtin.find:
paths: /etc/yum.repos.d
file_type: file
excludes: "myrepo.repo"
register: output
- name: Delete other files
ansible.builtin.file:
path: "{{ item.path }}"
state: absent
loop: "{{ output.files }}"
- name: Check for marker line
ansible.builtin.lineinfile:
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
ansible.builtin.file:
path: /etc/yum.repos.d/myrepo.repo
state: absent
when: marker_check.changed