<commit_before>---

- name: provision > find all template files
  command: "find -type f -printf '%P\n'"
  args:
    chdir: "{{ proxmoxy_templates_dir }}"
  changed_when: false
  register: __proxmoxy_prov_reg_templates

- name: provision > get list of current VMIDs
  shell: >
    pct list | cut -f1 -d' ' | grep -iv VMID || echo 'empty'
  changed_when: false
  register: __proxmoxy_prov_reg_vmids

# Compute the right ostemplate file for every container.
# ostemplate can contain a (regex) pattern to match the filename, i.e. "centos-7.*20160404.*"
# complicated statement, therefor outsourced to its own set_fact var
- name: provision > populate matching templates for all containers
  set_fact:
    __proxmoxy_ct_template_match: "{{ __proxmoxy_ct_template_match|default({}) | combine( {item.vmid: __proxmoxy_prov_reg_templates.stdout_lines|select('search', item.ostemplate|default(proxmoxy_templates_default))|sort|last|string} ) }}"
  with_items: "{{ proxmoxy_provision_containers }}"

- name: provision > configure lxc container
  proxmox_prov:
    state: "{{ item.state|default('present') }}"
    vmid: "{{ item.vmid }}"
    password: "{{ lookup('password', secret|d('secret') + '/cred/' + ansible_fqdn + '/root/pw length=20') if proxmoxy_provision_secret else item.password|default(omit) }}"
    hostname: "{{ item.hostname|default('newlxc') }}"
    ostemplate: "{{ proxmoxy_templates_dir }}/{{ __proxmoxy_ct_template_match[item.vmid]|default(omit) }}"
    arch: "{{ item.arch|default(omit) }}"
    cmode: "{{ item.cmode|default(omit) }}"
    console: "{{ item.console|default(omit) }}"
    cores: "{{ item.cores|default(omit) }}"
    cpuunits: "{{ item.cpuunits|default(omit) }}"
    description: "{{ item.description|default(omit) }}"
    memory: "{{ item.memory|default(omit) }}"
    mp0: "{{ item.mp0|default(omit) }}"
    mp1: "{{ item.mp1|default(omit) }}"
    mp2: "{{ item.mp2|default(omit) }}"
    mp3: "{{ item.mp3|default(omit) }}"
    mp4: "{{ item.mp4|default(omit) }}"
    mp5: "{{ item.mp5|default(omit) }}"
    mp6: "{{ item.mp6|default(omit) }}"
    mp7: "{{ item.mp7|default(omit) }}"
    mp8: "{{ item.mp8|default(omit) }}"
    mp9: "{{ item.mp9|default(omit) }}"
    net0: "{{ item.net0|default(omit) }}"
    net1: "{{ item.net1|default(omit) }}"
    net2: "{{ item.net2|default(omit) }}"
    net3: "{{ item.net3|default(omit) }}"
    net4: "{{ item.net4|default(omit) }}"
    net5: "{{ item.net5|default(omit) }}"
    net6: "{{ item.net6|default(omit) }}"
    net7: "{{ item.net7|default(omit) }}"
    net8: "{{ item.net8|default(omit) }}"
    net9: "{{ item.net9|default(omit) }}"
    node: "{{ item.node|default(omit) }}"
    onboot: "{{ item.onboot|default(omit) }}"
    ostype: "{{ item.ostype|default(omit) }}"
    pool: "{{ item.pool|default(omit) }}"
    protection: "{{ item.protection|default(omit) }}"
    rootfs: "{{ item.rootfs|default(omit) }}"
    searchdomain: "{{ item.searchdomain|default(omit) }}"
    ssh_public_keys: "{{ item.ssh_public_keys|default(omit) }}"
    startup: "{{ item.startup|default(omit) }}"
    storage: "{{ item.storage|default(omit) }}"
    swap: "{{ item.swap|default(omit) }}"
    tty: "{{ item.tty|default(omit) }}"
    unprivileged: "{{ item.unprivileged|default(omit) }}"
  with_items: "{{ proxmoxy_provision_containers }}"
  register: __proxmoxy_register_containers

# If vm (vmid) was not here before (on top), it must be a new VM.
- debug:
    var: item.item.vmid
    verbosity: 1
  when: item.item.vmid|string not in __proxmoxy_prov_reg_vmids.stdout_lines
  with_items: "{{ __proxmoxy_register_containers.results }}"

- name: Provision > start new containers
  shell: >
    pct start {{ item.item.vmid | d() }}
  when: item and item.item.vmid | string not in __proxmoxy_prov_reg_vmids.stdout_lines
  with_items:
    - "{{ __proxmoxy_register_containers.results|d([]) }}"

- name: Provision > execute commands on new containers
  shell: >
    echo '{{ item[1] }}' | pct enter {{ item[0].item.vmid|d() }}
  when: item[0] and item[0].item.vmid|string not in __proxmoxy_prov_reg_vmids.stdout_lines
  with_nested:
    - "{{ __proxmoxy_register_containers.results|d([]) }}"
    - "{{ proxmoxy_provision_post_cmds|d([]) }}"
  
- name: Provision > stop new containers, unless onboot
  shell: >
    pct stop {{ item.item.vmid|d() }}
  when: item and (item.item.vmid|string not in __proxmoxy_prov_reg_vmids.stdout_lines) and not item.item.onboot|d(False)|bool
  with_items:
    - "{{ __proxmoxy_register_containers.results|d([]) }}"<commit_msg>ignore errors from commands in containers<commit_after>---

- name: provision > find all template files
  command: "find -type f -printf '%P\n'"
  args:
    chdir: "{{ proxmoxy_templates_dir }}"
  changed_when: false
  register: __proxmoxy_prov_reg_templates

- name: provision > get list of current VMIDs
  shell: >
    pct list | cut -f1 -d' ' | grep -iv VMID || echo 'empty'
  changed_when: false
  register: __proxmoxy_prov_reg_vmids

# Compute the right ostemplate file for every container.
# ostemplate can contain a (regex) pattern to match the filename, i.e. "centos-7.*20160404.*"
# complicated statement, therefor outsourced to its own set_fact var
- name: provision > populate matching templates for all containers
  set_fact:
    __proxmoxy_ct_template_match: "{{ __proxmoxy_ct_template_match|default({}) | combine( {item.vmid: __proxmoxy_prov_reg_templates.stdout_lines|select('search', item.ostemplate|default(proxmoxy_templates_default))|sort|last|string} ) }}"
  with_items: "{{ proxmoxy_provision_containers }}"

- name: provision > configure lxc container
  proxmox_prov:
    state: "{{ item.state|default('present') }}"
    vmid: "{{ item.vmid }}"
    password: "{{ lookup('password', secret|d('secret') + '/cred/' + ansible_fqdn + '/root/pw length=20') if proxmoxy_provision_secret else item.password|default(omit) }}"
    hostname: "{{ item.hostname|default('newlxc') }}"
    ostemplate: "{{ proxmoxy_templates_dir }}/{{ __proxmoxy_ct_template_match[item.vmid]|default(omit) }}"
    arch: "{{ item.arch|default(omit) }}"
    cmode: "{{ item.cmode|default(omit) }}"
    console: "{{ item.console|default(omit) }}"
    cores: "{{ item.cores|default(omit) }}"
    cpuunits: "{{ item.cpuunits|default(omit) }}"
    description: "{{ item.description|default(omit) }}"
    memory: "{{ item.memory|default(omit) }}"
    mp0: "{{ item.mp0|default(omit) }}"
    mp1: "{{ item.mp1|default(omit) }}"
    mp2: "{{ item.mp2|default(omit) }}"
    mp3: "{{ item.mp3|default(omit) }}"
    mp4: "{{ item.mp4|default(omit) }}"
    mp5: "{{ item.mp5|default(omit) }}"
    mp6: "{{ item.mp6|default(omit) }}"
    mp7: "{{ item.mp7|default(omit) }}"
    mp8: "{{ item.mp8|default(omit) }}"
    mp9: "{{ item.mp9|default(omit) }}"
    net0: "{{ item.net0|default(omit) }}"
    net1: "{{ item.net1|default(omit) }}"
    net2: "{{ item.net2|default(omit) }}"
    net3: "{{ item.net3|default(omit) }}"
    net4: "{{ item.net4|default(omit) }}"
    net5: "{{ item.net5|default(omit) }}"
    net6: "{{ item.net6|default(omit) }}"
    net7: "{{ item.net7|default(omit) }}"
    net8: "{{ item.net8|default(omit) }}"
    net9: "{{ item.net9|default(omit) }}"
    node: "{{ item.node|default(omit) }}"
    onboot: "{{ item.onboot|default(omit) }}"
    ostype: "{{ item.ostype|default(omit) }}"
    pool: "{{ item.pool|default(omit) }}"
    protection: "{{ item.protection|default(omit) }}"
    rootfs: "{{ item.rootfs|default(omit) }}"
    searchdomain: "{{ item.searchdomain|default(omit) }}"
    ssh_public_keys: "{{ item.ssh_public_keys|default(omit) }}"
    startup: "{{ item.startup|default(omit) }}"
    storage: "{{ item.storage|default(omit) }}"
    swap: "{{ item.swap|default(omit) }}"
    tty: "{{ item.tty|default(omit) }}"
    unprivileged: "{{ item.unprivileged|default(omit) }}"
  with_items: "{{ proxmoxy_provision_containers }}"
  register: __proxmoxy_register_containers

# If vm (vmid) was not here before (on top), it must be a new VM.
- debug:
    var: item.item.vmid
    verbosity: 1
  when: item.item.vmid|string not in __proxmoxy_prov_reg_vmids.stdout_lines
  with_items: "{{ __proxmoxy_register_containers.results }}"

- name: Provision > start new containers
  shell: >
    pct start {{ item.item.vmid | d() }}
  when: item and item.item.vmid | string not in __proxmoxy_prov_reg_vmids.stdout_lines
  with_items:
    - "{{ __proxmoxy_register_containers.results|d([]) }}"

- name: Provision > execute commands on new containers
  shell: >
    echo '{{ item[1] }}' | pct enter {{ item[0].item.vmid|d() }}
  when: item[0] and item[0].item.vmid|string not in __proxmoxy_prov_reg_vmids.stdout_lines
  with_nested:
    - "{{ __proxmoxy_register_containers.results|d([]) }}"
    - "{{ proxmoxy_provision_post_cmds|d([]) }}"
  ignore_errors: True

- name: Provision > stop new containers, unless onboot
  shell: >
    pct stop {{ item.item.vmid|d() }}
  when: item and (item.item.vmid|string not in __proxmoxy_prov_reg_vmids.stdout_lines) and not item.item.onboot|d(False)|bool
  with_items:
    - "{{ __proxmoxy_register_containers.results|d([]) }}"
{'fraction_non_alphanumeric': 0.17765769739744156, 'fraction_numerical': 0.012571680635200706, 'mean_word_length': 4.39179548156956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3657483', 'n_tokens_mistral': 3480, 'n_tokens_neox': 3361, 'n_words': 589}