<commit_before>---
# file: roles/libvirt_guests_terminate/tasks/main.yml

- name: Remove static local IP addresses from /etc/hosts
  sudo: yes
  lineinfile: >
              dest="/etc/hosts"
              regexp='^[^ \t]*[ \t]+{{ item }}[ \t]+'
              state=absent
  with_items: groups['ex_{{ libvirt_guests_group | mandatory }}']

- name: Remove static local IP addresses from the libvirt default network
  sudo: yes
  lineinfile: >
              dest="/etc/libvirt/qemu/networks/default.xml"
              regexp='^[ \t]+<host[ \t]+.*name="{{ item }}"'
              state=absent
  with_items: groups['ex_{{ libvirt_guests_group }}']

- name: Destroy the guest domain
  sudo: yes
  virt: name="{{ item }}" command=destroy state=destroyed
  with_items: groups['ex_{{ libvirt_guests_group }}']
  ignore_errors: yes

- name: Undefine the guest domain
  sudo: yes
  virt: name="{{ item }}" command=undefine
  with_items: groups['ex_{{ libvirt_guests_group }}']
  ignore_errors: yes

- name: Delete DNS SSHFP records
  local_action: >
                command curl -s -X DELETE -H 'Content-Type: application/json'
                -H 'Auth-Token: {{ dynect_session_token }}'
                {{ dynect_api_url }}/SSHFPRecord/{{ dns_zone | mandatory }}/{{ item }}/
  with_items: groups['ex_{{ libvirt_guests_group }}']
  ignore_errors: yes

- name: Check if SSH known hosts file exists
  stat: path="~/.ssh/known_hosts"
  register: known_hosts

- name: Remove FQDNs from SSH known hosts
  command: ssh-keygen -R {{ item }}
  with_items: groups['ex_{{ libvirt_guests_group }}']
  when: known_hosts.stat.exists
  ignore_errors: yes

- name: Remove FQDNs (admin port) from SSH known hosts
  command: ssh-keygen -R "[{{ item }}]:{{ admin_ssh_port }}"
  with_items: groups['ex_{{ libvirt_guests_group }}']
  when: known_hosts.stat.exists
  ignore_errors: yes

- name: Remove simple hostnames from SSH known hosts
  command: ssh-keygen -R {{ item | regex_replace("^([^\.]*)\..*$", "\\1") }}
  with_items: groups['ex_{{ libvirt_guests_group }}']
  when: known_hosts.stat.exists
  ignore_errors: yes

- name: Remove simple hostnames (admin port) from SSH known hosts
  command: ssh-keygen -R "[{{ item | regex_replace("^([^\.]*)\..*$", "\\1") }}]:{{ admin_ssh_port }}"
  with_items: groups['ex_{{ libvirt_guests_group }}']
  when: known_hosts.stat.exists
  ignore_errors: yes<commit_msg>DNS SSHFP records termination<commit_after>---
# file: roles/libvirt_guests_terminate/tasks/main.yml

- name: Remove static local IP addresses from /etc/hosts
  sudo: yes
  lineinfile: >
              dest="/etc/hosts"
              regexp='^[^ \t]*[ \t]+{{ item }}[ \t]+'
              state=absent
  with_items: groups['ex_{{ libvirt_guests_group | mandatory }}']

- name: Remove static local IP addresses from the libvirt default network
  sudo: yes
  lineinfile: >
              dest="/etc/libvirt/qemu/networks/default.xml"
              regexp='^[ \t]+<host[ \t]+.*name="{{ item }}"'
              state=absent
  with_items: groups['ex_{{ libvirt_guests_group }}']

- name: Destroy the guest domain
  sudo: yes
  virt: name="{{ item }}" command=destroy state=destroyed
  with_items: groups['ex_{{ libvirt_guests_group }}']
  ignore_errors: yes

- name: Undefine the guest domain
  sudo: yes
  virt: name="{{ item }}" command=undefine
  with_items: groups['ex_{{ libvirt_guests_group }}']
  ignore_errors: yes

- name: Delete DNS SSHFP records
  when: dynect_session_result|success
  local_action: >
                command curl -s -X DELETE -H 'Content-Type: application/json'
                -H 'Auth-Token: {{ dynect_session_token }}'
                {{ dynect_api_url }}/SSHFPRecord/{{ dns_zone | mandatory }}/{{ item }}/
  with_items: groups['ex_{{ libvirt_guests_group }}']
  ignore_errors: yes

- name: Publish DNS zones
  when: dynect_session_result|success
  local_action: >
                command curl -s -X PUT -H 'Content-Type: application/json'
                -H 'Auth-Token: {{ dynect_session_token }}'
                {{ dynect_api_url }}/Zone/{{ dns_zone }} -d '{"publish":true}'

- name: Check if SSH known hosts file exists
  stat: path="~/.ssh/known_hosts"
  register: known_hosts

- name: Remove FQDNs from SSH known hosts
  command: ssh-keygen -R {{ item }}
  with_items: groups['ex_{{ libvirt_guests_group }}']
  when: known_hosts.stat.exists
  ignore_errors: yes

- name: Remove FQDNs (admin port) from SSH known hosts
  command: ssh-keygen -R "[{{ item }}]:{{ admin_ssh_port }}"
  with_items: groups['ex_{{ libvirt_guests_group }}']
  when: known_hosts.stat.exists
  ignore_errors: yes

- name: Remove simple hostnames from SSH known hosts
  command: ssh-keygen -R {{ item | regex_replace("^([^\.]*)\..*$", "\\1") }}
  with_items: groups['ex_{{ libvirt_guests_group }}']
  when: known_hosts.stat.exists
  ignore_errors: yes

- name: Remove simple hostnames (admin port) from SSH known hosts
  command: ssh-keygen -R "[{{ item | regex_replace("^([^\.]*)\..*$", "\\1") }}]:{{ admin_ssh_port }}"
  with_items: groups['ex_{{ libvirt_guests_group }}']
  when: known_hosts.stat.exists
  ignore_errors: yes
{'fraction_non_alphanumeric': 0.15091015854374634, 'fraction_numerical': 0.0007829320806420043, 'mean_word_length': 3.341546304163127, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2970596', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1679, 'n_words': 435}