# Unnstall ovn
# This is done when installed ovn is no longer needed

# On a convienent host, clone ovn-kubernetes cd to dist/ansible 
# git clone https://github.com/ovn-org/ovn-kubernetes ~/ovn-kubernetes
# cd ~/ovn-kubernetes/dist/ansible

# edit hosts file for the hostname of the master

# ./run-playbook

- hosts: masters
  become: yes
  become_user: root
  tasks:
  - name: Delete the OVN Namespace
    shell: oc delete -f /root/ovn/yaml/ovn-setup.yaml
    ignore_errors: yes

  # remove /root/ovn
  - name: Remove /root/ovn
    shell: rm -rf /root/ovn/*

  # OVN data is persistent, so delete the database
  - name: Remove OVN nb DB Content
    file:
      state: absent
      name: /var/lib/openvswitch/ovnnb_db.db
  - name: Remove OVN sb DB Content
    file:
      state: absent
      name: /var/lib/openvswitch/ovnsb_db.db

  # iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport 6641 -j ACCEPT
  - name: iptables allow 6641
    shell: iptables -D INPUT -p tcp -m tcp --dport 6641 -m conntrack --ctstate NEW -j ACCEPT
    ignore_errors: yes

  # iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport 6642 -j ACCEPT
  - name: iptables allow 6642
    shell: iptables -D INPUT -p tcp -m tcp --dport 6642 -m conntrack --ctstate NEW -j ACCEPT
    ignore_errors: yes

# - name: Add adm policy auyuid
#   shell: oc adm policy add-scc-to-user anyuid -z ovn
#   ignore_errors: yes


- hosts: nodes
  become: yes
  become_user: root
  tasks:
  - name: Remove remove the cni plugin config
    file:
      state: absent
      name: /etc/cni/net.d/10-ovn-kubernetes.conf
  - name: Remove ovn-k8s-cni-overlay
    file:
      state: absent
      name: /opt/cni/bin/ovn-k8s-cni-overlay

  - name: Remove old log files
    shell: rm -rf /var/log/openvswitch/ovn*log /var/log/openvswitch/ovs*log

  - name: remove old unix sockets
    shell: rm -rf /var/run/openvswitch/ovn*ctl /var/run/openvswitch/ovn*pid /var/run/openvswitch/ovs*ctl /var/run/openvswitch/ovs*pid /var/run/openvswitch/ovn?b_db.sock

  - name: Remove OVS DB Content
    file:
      state: absent
      name: /etc/origin/openvswitch/conf.db
  - name: Remove OVS system id Content
    file:
      state: absent
      name: /etc/origin/openvswitch/system-id.conf
