Technotes

Technotes for future me

Ansible remove file

    ###################
    # Remove temp files
    ###################

    # RHEL 5 Remove temporary ldap.conf_new file
    - name: RHEL 5 Remove temporary ldap.conf_new file
      file:
        path: /etc/ldap.conf_new
        state: absent
      when: "ansible_distribution_major_version == '5'"

    # RHEL 6 and 7 Remove temporary pam_ldap.conf_new file
    - name: Delete temporary file pam_ldap.conf_new file
      file:
        path: /etc/pam_ldap.conf_new
        state: absent
      when: (ansible_facts['distribution_major_version'] == "6") or (ansible_facts['distribution_major_version'] == "7")

    # RHEL 6 and 7 Remove temporary file
    - name: Delete temporary nslcd.conf_new file
      file:
        path: /etc/nslcd.conf_new
        state: absent
      when: (ansible_facts['distribution_major_version'] == "6") or (ansible_facts['distribution_major_version'] == "7")
---
- hosts: all
  become_user: root
  become: yes
  become_method: sudo
  gather_facts: no
  tasks:
  - name: Remove file (delete file)
    file:
      path: /etc/yum.repos.d/broken.repo
      state: absent
...
Last updated on 31 Jan 2021
Published on 16 Dec 2019
Edit on GitHub