<commit_before># Setting facts here rather than vars/ since it's the only place it's being used
- set_fact:
      base_image: "{{ (provisioner.image.server is defined) | ternary(provisioner.image.file|default(''), provisioner.image.url|basename) }}"
      base_image_path: /var/lib/libvirt/images
      url: "{{ (provisioner.image.server is defined) | ternary(provisioner.image.server|default('') + '/' + provisioner.image.file|default(''), provisioner.image.url) }}"

# to not have to repeat base image download/setup
# (nodes.count * node.disks.count) times (very big waste of time)
# we do small math/logic here
# ... we need to look in all nodes and their disk definitions
# ... if there is at least one without import_url (and so needs base image)
# ... (all is dictionary, no lists, so no simple map/selectattr can be used)
# dbi_ prefix here is used to not limit these vars kind of here
#      stands for download-base-image
- name: "get all disks dictionaries"
  set_fact:
      dbi_disks_dict: "{{ provisioner.topology.nodes.values() | map(attribute='disks') | list }}"  # | map(attribute='disks') | list }}"  # last sum is list flattening

- name: "define acummulator var"
  set_fact:
      dbi_disks_list: []

- name: "accumulate all disks dictionaries contents"
  set_fact:
      dbi_disks_list: "{{ dbi_disks_list + item.values() }}"
  with_items: "{{ dbi_disks_dict }}"

- name: "find all disks with import_url"
  set_fact:
      dbi_disks_imported: "{{ dbi_disks_list | selectattr('import_url', 'defined') | selectattr('import_url') | list }}"

- name: "check if we have any not imported disk"
  set_fact:
      dbi_any_not_imported: "{{ dbi_disks_list|length > dbi_disks_imported|length }}"

- block:
    - name: download base image
      get_url:
          url: "{{ url }}"
          dest: "~/{{ base_image }}.original"
          validate_certs: "{{ url.startswith('https://url.corp.redhat.com/') | ternary(false, omit)}}"
          timeout: 30
      register: download_image_result
      until: download_image_result.msg.find("Request failed") == -1
      retries: 5
      delay: 5

    - name: copy base image for adjusting
      copy:
          remote_src: True
          src: "~/{{ base_image }}.original"
          dest: "{{ base_image_path }}/{{ base_image }}"
          owner: qemu
          group: qemu

    - name: adjust base image for this run
      shell: |
          set -x
          virt-sysprep -a {{ base_image_path }}/{{ base_image }} \
              --operations dhcp-client-state,dhcp-server-state,net-hostname,net-hwaddr,udev-persistent-net

          virt-customize -a {{ base_image_path }}/{{ base_image }} \
              --run-command 'yum remove -y cloud-init*' \
              --root-password password:<PASSWORD> \
              --mkdir /root/.ssh \
              --chmod 0700:/root/.ssh \
              --upload /root/.ssh/id_rsa.pub:/root/.ssh/authorized_keys \
              --selinux-relabel

  when: dbi_any_not_imported is defined and dbi_any_not_imported

# now continue with creating vm's
# Import disk images if necessary
- name: "import disks for each VM if specified"
  include: "vms_0_import_disk.yml"
  with_dict: "{{ provisioner.topology.nodes }}"
  loop_control:
      loop_var: node

- name: "create disks for each VM if not import"
  include: "vms_1_create_disk.yml"

# Build our VMs
- name: "define libvirt VMs"
  include: "vms_2_install.yml"
  with_dict: "{{ provisioner.topology.nodes }}"
  loop_control:
      loop_var: node

- name: "wait for VMs to come up, fix their ip and add to inventory"
  include: "vms_3_netip.yml"
  with_dict: "{{ provisioner.topology.nodes }}"
  loop_control:
      loop_var: node

- name: "update ansible.ssh.config template"
  template:
      src: ansible.ssh.config.j2
      dest: "{{ inventory_dir }}/ansible.ssh.config"
  delegate_to: localhost
<commit_msg>Have the sshd to do less DNS lookups<commit_after># Setting facts here rather than vars/ since it's the only place it's being used
- set_fact:
      base_image: "{{ (provisioner.image.server is defined) | ternary(provisioner.image.file|default(''), provisioner.image.url|basename) }}"
      base_image_path: /var/lib/libvirt/images
      url: "{{ (provisioner.image.server is defined) | ternary(provisioner.image.server|default('') + '/' + provisioner.image.file|default(''), provisioner.image.url) }}"

# to not have to repeat base image download/setup
# (nodes.count * node.disks.count) times (very big waste of time)
# we do small math/logic here
# ... we need to look in all nodes and their disk definitions
# ... if there is at least one without import_url (and so needs base image)
# ... (all is dictionary, no lists, so no simple map/selectattr can be used)
# dbi_ prefix here is used to not limit these vars kind of here
#      stands for download-base-image
- name: "get all disks dictionaries"
  set_fact:
      dbi_disks_dict: "{{ provisioner.topology.nodes.values() | map(attribute='disks') | list }}"  # | map(attribute='disks') | list }}"  # last sum is list flattening

- name: "define acummulator var"
  set_fact:
      dbi_disks_list: []

- name: "accumulate all disks dictionaries contents"
  set_fact:
      dbi_disks_list: "{{ dbi_disks_list + item.values() }}"
  with_items: "{{ dbi_disks_dict }}"

- name: "find all disks with import_url"
  set_fact:
      dbi_disks_imported: "{{ dbi_disks_list | selectattr('import_url', 'defined') | selectattr('import_url') | list }}"

- name: "check if we have any not imported disk"
  set_fact:
      dbi_any_not_imported: "{{ dbi_disks_list|length > dbi_disks_imported|length }}"

- block:
    - name: download base image
      get_url:
          url: "{{ url }}"
          dest: "~/{{ base_image }}.original"
          validate_certs: "{{ url.startswith('https://url.corp.redhat.com/') | ternary(false, omit)}}"
          timeout: 30
      register: download_image_result
      until: download_image_result.msg.find("Request failed") == -1
      retries: 5
      delay: 5

    - name: copy base image for adjusting
      copy:
          remote_src: True
          src: "~/{{ base_image }}.original"
          dest: "{{ base_image_path }}/{{ base_image }}"
          owner: qemu
          group: qemu

    - name: adjust base image for this run
      shell: |
          set -x
          virt-sysprep -a {{ base_image_path }}/{{ base_image }} \
              --operations dhcp-client-state,dhcp-server-state,net-hostname,net-hwaddr,udev-persistent-net

          virt-customize -a {{ base_image_path }}/{{ base_image }} \
              --run-command 'yum remove -y cloud-init*' \
              --root-password password:<PASSWORD> \
              --run-command 'echo "UseDNS no" >> /etc/ssh/sshd_config' \
              --mkdir /root/.ssh \
              --chmod 0700:/root/.ssh \
              --upload /root/.ssh/id_rsa.pub:/root/.ssh/authorized_keys \
              --selinux-relabel

  when: dbi_any_not_imported is defined and dbi_any_not_imported

# now continue with creating vm's
# Import disk images if necessary
- name: "import disks for each VM if specified"
  include: "vms_0_import_disk.yml"
  with_dict: "{{ provisioner.topology.nodes }}"
  loop_control:
      loop_var: node

- name: "create disks for each VM if not import"
  include: "vms_1_create_disk.yml"

# Build our VMs
- name: "define libvirt VMs"
  include: "vms_2_install.yml"
  with_dict: "{{ provisioner.topology.nodes }}"
  loop_control:
      loop_var: node

- name: "wait for VMs to come up, fix their ip and add to inventory"
  include: "vms_3_netip.yml"
  with_dict: "{{ provisioner.topology.nodes }}"
  loop_control:
      loop_var: node

- name: "update ansible.ssh.config template"
  template:
      src: ansible.ssh.config.j2
      dest: "{{ inventory_dir }}/ansible.ssh.config"
  delegate_to: localhost

{'fraction_non_alphanumeric': 0.12647360328036905, 'fraction_numerical': 0.0035879036391594054, 'mean_word_length': 2.9025, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '394712', 'n_tokens_mistral': 2644, 'n_tokens_neox': 2543, 'n_words': 680}