---
- name: Clear proxy settings from the system
  hosts: all
  become: yes
  gather_facts: false

  tasks:
    - name: Remove proxy environment file
      file:
        path: /root/mgmt/configuration/proxy.env
        state: absent
      ignore_errors: yes

    - name: Unset proxy environment variables
      shell: |
        unset http_proxy
        unset https_proxy
        unset HTTP_PROXY
        unset HTTPS_PROXY
        unset no_proxy
        unset NO_PROXY
        unset ALL_PROXY
        unset all_proxy
        unset DOCKER_BUILDKIT
        unset BUILDKIT_PROGRESS
        unset GIT_HTTP_PROXY
        unset GIT_HTTPS_PROXY
        unset CURL_PROXY
        unset WGET_PROXY
      ignore_errors: yes

    - name: Remove proxy settings from /etc/environment
      lineinfile:
        path: /etc/environment
        state: absent
        regexp: '^(http_proxy|https_proxy|no_proxy|ALL_PROXY|DOCKER_BUILDKIT|BUILDKIT_PROGRESS|GIT_HTTP_PROXY|GIT_HTTPS_PROXY|CURL_PROXY|WGET_PROXY)='
      ignore_errors: yes

    - name: Remove proxy settings from /etc/apt/apt.conf.d/proxy.conf
      file:
        path: /etc/apt/apt.conf.d/proxy.conf
        state: absent
      ignore_errors: yes

    - name: Display completion message
      debug:
        msg: "Proxy settings have been cleared from the system."