<commit_before>---
## Bootstrap python for ansible python modules
#
#    if ansible_python_interpreter is not set:
#        try to find a valid python interpreter
#        if find failed:
#            try to install a python interpreter
#        set ansible_python_interpreter
#    test run the ping module at last

- block:

  - name: detect installed python
    register: detect_installed_python
    vars:
    - raw_script: |-
        {{ shell_export }} PY{{ shell_export_eq }}/usr/bin/python
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}python2.7
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}python27
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}python2
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}python2.6
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}python26
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}pyrun2.7
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}pyrun
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}pypy
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}{{ ( '/opt/exxo-python-' + exxo_version + '-' + exxo_installer_version ) | quote }}/bin/python
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}{{ ( '/var/tmp/exxo-python-' + exxo_version + '-' + exxo_installer_version ) | quote }}/bin/python
        {{ shell_exit_if_python_is_valid }}
        exit 41
    raw: "{{ shell_exec | quote }} -c {{ raw_script | quote }}"
    failed_when: ( [ detect_installed_python.rc | d(0) ]
                   | difference([0, 41])
                   | list
                   | length == 1
                 ) or ( detect_installed_python.rc | d(1) == 0
                        and detect_installed_python.stdout_lines | last | d('') == '')
    changed_when: False

  - block:

    - name: remote is root?
      register: remote_is_root
      raw: id -u
      ignore_errors: True
      changed_when: False

    - name: remote is Linux X64 with gblic
      register: remote_linux_x64_gblic
      script: "{{ role_path }}/files/detect-linux-x64-gcc"
      ignore_errors: True
      failed_when: remote_linux_x64_gblic.rc | d(0) != 42
      changed_when: False

    # python bootstrap for ansible
    # reference:
    #   [0]: https://github.com/dochang/ansible-role-bootstrap/
    #   [1]: https://github.com/bambocher/ansible-role-bootstrap/
    # Apt:
    #   - Install `python-apt` which is required by Ansible `apt` module.
    # zypper:
    #   - zypper must be checked before yum since zypper uses yum as backend.
    #   - Install `python-xml`, because the Ansible module `zypper_repository` depends on it.
    # yum:
    #   - Install `yum-utils`.  Ansible `yum` module requires `repoquery`,
    #     which is provided by `yum-utils`, to use `list` parameter.
    # dnf:
    #   - Install `python2-dnf`, which is required by Ansible `dnf` module.
    # emerge:
    #   - Install `gentoolkit`, which contains `equery`. `gentoolkit` is also required by Ansible `portage` module.
    - name: installing python
      register: installing_python
      vars:
      - exxo_deploy_dir: "{{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('/opt', '/var/tmp') }}/exxo-python-{{ exxo_version }}-{{ exxo_installer_version }}"
      - raw_script: |-
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which apt-get', 'false') }} \
              {{ shell_and }} {{ shell_export }} DEBIAN_FRONTEND{{ shell_export_eq }}noninteractive \
              {{ shell_and }} apt-get --quiet=2 --option 'Acquire::Languages=none' update \
              {{ shell_and }} apt-get --quiet=2 --assume-yes install python python-dev python-apt \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which zypper', 'false') }} \
              {{ shell_and }} zypper --quiet refresh \
              {{ shell_and }} zypper --quiet --non-interactive install --auto-agree-with-licenses python python-devel python-xml \
              {{ shell_and }} exit 0
          which zypper
          test {{ shell_err_code }} != 0 {{ shell_and }} \
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which yum', 'false') }} \
              {{ shell_and }} yum --quiet makecache fast \
              {{ shell_and }} yum --quiet --assumeyes install python python-devel yum-utils \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which pacman', 'false') }} \
              {{ shell_and }} pacman --sync --quiet --noconfirm --refresh python2 \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which dnf', 'false') }} \
              {{ shell_and }} dnf --quiet makecache fast \
              {{ shell_and }} dnf --quiet --assumeyes install python python-devel python2-dnf \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which emerge', 'false') }} \
              {{ shell_and }} emerge --quiet --sync \
              {{ shell_and }} emerge --quiet --ask n '=dev-lang/python-2*' gentoolkit \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which apk', 'false') }} \
              {{ shell_and }} apk add --quiet --update-cache python \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which pkg', 'false') }} \
              {{ shell_and }} pkg install -y python27 \
              {{ shell_and }} exit 0
          {{ (remote_linux_x64_gblic.rc | d(0) == 42) | ternary('true', 'exit 50') }}
          which wget {{ shell_or }} which curl {{ shell_or }} exit 51
          cd {{ shell_or }} exit 52
          mkdir -p {{ ('.ansible/tmp/exxo' + omit) | quote }} {{ shell_or }} exit 53
          cd {{ ('.ansible/tmp/exxo' + omit) | quote }} {{ shell_or }} exit 54
          which wget {{ shell_and }} wget -O - -- {{ exxo_url | quote }} | tar {{ ( 'x' + exxo_untar_flags + 'vf' ) | quote }} -
          test {{ shell_err_code }} != 0 \
               {{ shell_and }} rm -f exxo \
               {{ shell_and }} which curl \
               {{ shell_and }} curl -L --insecure -o - -- {{ exxo_url | quote }}  | tar {{ ( 'x' + exxo_untar_flags + 'vf' ) | quote }} -
          test -x exxo \
               {{ shell_and }} mkdir -p -- {{ exxo_deploy_dir | quote }} \
               {{ shell_and }} ./exxo venv -p 2.7 -- {{ exxo_deploy_dir | quote }} \
               {{ shell_and }} {{ shell_export }} PY{{ shell_export_eq }}{{ exxo_deploy_dir + '/bin/python' | quote }} \
               {{ shell_and }} {{ shell_exit_if_python_is_valid }}
          cd {{ shell_and }} rm -rf -- {{ ('.ansible/tmp/exxo' + omit) | quote }}
          exit 55
      raw: "{{ shell_exec | quote }} -c {{ raw_script | quote }}"

    - name: detect installed python again
      register: detect_installed_python_2
      vars:
      - raw_script: |-
          {{ shell_export }} PY{{ shell_export_eq }}/usr/bin/python
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}python2.7
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}python27
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}python2
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}python2.6
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}python26
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}pyrun2.7
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}pyrun
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}pypy
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}{{ ( '/opt/exxo-python-' + exxo_version + '-' + exxo_installer_version ) | quote }}/bin/python
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}{{ ( '/var/tmp/exxo-python-' + exxo_version + '-' + exxo_installer_version ) | quote }}/bin/python
          {{ shell_exit_if_python_is_valid }}
          echo "Unsupported platforms!"
          exit 43
      raw: "{{ shell_exec | quote }} -c {{ raw_script | quote }}"
      failed_when: detect_installed_python_2.rc | d(1) != 0 or detect_installed_python_2.stdout_lines | last | d('') == ''
      changed_when: False

    when: detect_installed_python.rc | d(1) == 41

  - name: set ansible_python_interpreter
    set_fact:
      ansible_python_interpreter: "{{ ( (detect_installed_python.rc | d(1) == 0)
                                      | ternary(detect_installed_python, detect_installed_python_2) ).stdout_lines | last }}"
    when: "{{ ( (detect_installed_python.rc | d(1) == 0)
              | ternary(detect_installed_python, detect_installed_python_2) ).stdout_lines | last != '/usr/bin/python' }}"

  vars:
  - shell_exec: >-
        {{ ( [ansible_shell_type | d('sh')]
             | intersect(['sh', 'csh', 'fish'])
             | list
             | length == 1
             and ansible_version.full | version_compare('2.1', '>='))
           | ternary(ansible_shell_executable, '/bin/sh')
        }}
  - shell_type: >-
        {{ ( [ansible_shell_type | d('')]
             | intersect(['sh', 'csh', 'fish'])
             | list
             | length == 1 )
           | ternary(ansible_shell_type, 'sh')
        }}
  - shell_err_code:  "{{ (shell_type == 'sh')   | ternary('$?',     '$status') }}"
  - shell_and:       "{{ (shell_type == 'fish') | ternary('; and',  '&&')      }}"
  - shell_or:        "{{ (shell_type == 'fish') | ternary('; or',   '||')      }}"
  - shell_export:    "{{ (shell_type == 'csh')  | ternary('setenv', 'export')  }}"
  - shell_export_eq: "{{ (shell_type == 'csh')  | ternary(' ',      '=')       }}"
  - shell_exit_if_python_is_valid: >
        "$PY" -c 'import sys; sys.exit(not (sys.hexversion >= 0x02060000 and sys.hexversion < 0x03000000))'
        {{ shell_and }} which "$PY"
        {{ shell_and }} exit 0
  - exxo_installer_version: "0"
  when: ansible_python_interpreter is not defined

- name: test ping
  ping:<commit_msg>fish shell requre eval a command defined by a environment variable<commit_after>---
## Bootstrap python for ansible python modules
#
#    if ansible_python_interpreter is not set:
#        try to find a valid python interpreter
#        if find failed:
#            try to install a python interpreter
#        set ansible_python_interpreter
#    test run the ping module at last

- block:

  - name: detect installed python
    register: detect_installed_python
    vars:
    - raw_script: |-
        {{ shell_export }} PY{{ shell_export_eq }}/usr/bin/python
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}python2.7
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}python27
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}python2
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}python2.6
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}python26
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}pyrun2.7
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}pyrun
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}pypy
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}{{ ( '/opt/exxo-python-' + exxo_version + '-' + exxo_installer_version ) | quote }}/bin/python
        {{ shell_exit_if_python_is_valid }}
        {{ shell_export }} PY{{ shell_export_eq }}{{ ( '/var/tmp/exxo-python-' + exxo_version + '-' + exxo_installer_version ) | quote }}/bin/python
        {{ shell_exit_if_python_is_valid }}
        exit 41
    raw: "{{ shell_exec | quote }} -c {{ raw_script | quote }}"
    failed_when: ( [ detect_installed_python.rc | d(0) ]
                   | difference([0, 41])
                   | list
                   | length == 1
                 ) or ( detect_installed_python.rc | d(1) == 0
                        and detect_installed_python.stdout_lines | last | d('') == '')
    changed_when: False

  - block:

    - name: remote is root?
      register: remote_is_root
      raw: id -u
      ignore_errors: True
      changed_when: False

    - name: remote is Linux X64 with gblic
      register: remote_linux_x64_gblic
      script: "{{ role_path }}/files/detect-linux-x64-gcc"
      ignore_errors: True
      failed_when: remote_linux_x64_gblic.rc | d(0) != 42
      changed_when: False

    # python bootstrap for ansible
    # reference:
    #   [0]: https://github.com/dochang/ansible-role-bootstrap/
    #   [1]: https://github.com/bambocher/ansible-role-bootstrap/
    # Apt:
    #   - Install `python-apt` which is required by Ansible `apt` module.
    # zypper:
    #   - zypper must be checked before yum since zypper uses yum as backend.
    #   - Install `python-xml`, because the Ansible module `zypper_repository` depends on it.
    # yum:
    #   - Install `yum-utils`.  Ansible `yum` module requires `repoquery`,
    #     which is provided by `yum-utils`, to use `list` parameter.
    # dnf:
    #   - Install `python2-dnf`, which is required by Ansible `dnf` module.
    # emerge:
    #   - Install `gentoolkit`, which contains `equery`. `gentoolkit` is also required by Ansible `portage` module.
    - name: installing python
      register: installing_python
      vars:
      - exxo_deploy_dir: "{{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('/opt', '/var/tmp') }}/exxo-python-{{ exxo_version }}-{{ exxo_installer_version }}"
      - raw_script: |-
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which apt-get', 'false') }} \
              {{ shell_and }} {{ shell_export }} DEBIAN_FRONTEND{{ shell_export_eq }}noninteractive \
              {{ shell_and }} apt-get --quiet=2 --option 'Acquire::Languages=none' update \
              {{ shell_and }} apt-get --quiet=2 --assume-yes install python python-dev python-apt \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which zypper', 'false') }} \
              {{ shell_and }} zypper --quiet refresh \
              {{ shell_and }} zypper --quiet --non-interactive install --auto-agree-with-licenses python python-devel python-xml \
              {{ shell_and }} exit 0
          which zypper
          test {{ shell_err_code }} != 0 {{ shell_and }} \
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which yum', 'false') }} \
              {{ shell_and }} yum --quiet makecache fast \
              {{ shell_and }} yum --quiet --assumeyes install python python-devel yum-utils \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which pacman', 'false') }} \
              {{ shell_and }} pacman --sync --quiet --noconfirm --refresh python2 \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which dnf', 'false') }} \
              {{ shell_and }} dnf --quiet makecache fast \
              {{ shell_and }} dnf --quiet --assumeyes install python python-devel python2-dnf \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which emerge', 'false') }} \
              {{ shell_and }} emerge --quiet --sync \
              {{ shell_and }} emerge --quiet --ask n '=dev-lang/python-2*' gentoolkit \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which apk', 'false') }} \
              {{ shell_and }} apk add --quiet --update-cache python \
              {{ shell_and }} exit 0
          {{ ( remote_is_root.stdout_lines | first | d('') == '0') | ternary('which pkg', 'false') }} \
              {{ shell_and }} pkg install -y python27 \
              {{ shell_and }} exit 0
          {{ (remote_linux_x64_gblic.rc | d(0) == 42) | ternary('true', 'exit 50') }}
          which wget {{ shell_or }} which curl {{ shell_or }} exit 51
          cd {{ shell_or }} exit 52
          mkdir -p {{ ('.ansible/tmp/exxo' + omit) | quote }} {{ shell_or }} exit 53
          cd {{ ('.ansible/tmp/exxo' + omit) | quote }} {{ shell_or }} exit 54
          which wget {{ shell_and }} wget -O - -- {{ exxo_url | quote }} | tar {{ ( 'x' + exxo_untar_flags + 'vf' ) | quote }} -
          test {{ shell_err_code }} != 0 \
               {{ shell_and }} rm -f exxo \
               {{ shell_and }} which curl \
               {{ shell_and }} curl -L --insecure -o - -- {{ exxo_url | quote }}  | tar {{ ( 'x' + exxo_untar_flags + 'vf' ) | quote }} -
          test -x exxo \
               {{ shell_and }} mkdir -p -- {{ exxo_deploy_dir | quote }} \
               {{ shell_and }} ./exxo venv -p 2.7 -- {{ exxo_deploy_dir | quote }} \
               {{ shell_and }} {{ shell_export }} PY{{ shell_export_eq }}{{ exxo_deploy_dir + '/bin/python' | quote }} \
               {{ shell_and }} {{ shell_exit_if_python_is_valid }}
          cd {{ shell_and }} rm -rf -- {{ ('.ansible/tmp/exxo' + omit) | quote }}
          exit 55
      raw: "{{ shell_exec | quote }} -c {{ raw_script | quote }}"

    - name: detect installed python again
      register: detect_installed_python_2
      vars:
      - raw_script: |-
          {{ shell_export }} PY{{ shell_export_eq }}/usr/bin/python
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}python2.7
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}python27
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}python2
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}python2.6
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}python26
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}pyrun2.7
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}pyrun
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}pypy
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}{{ ( '/opt/exxo-python-' + exxo_version + '-' + exxo_installer_version ) | quote }}/bin/python
          {{ shell_exit_if_python_is_valid }}
          {{ shell_export }} PY{{ shell_export_eq }}{{ ( '/var/tmp/exxo-python-' + exxo_version + '-' + exxo_installer_version ) | quote }}/bin/python
          {{ shell_exit_if_python_is_valid }}
          echo "Unsupported platforms!"
          exit 43
      raw: "{{ shell_exec | quote }} -c {{ raw_script | quote }}"
      failed_when: detect_installed_python_2.rc | d(1) != 0 or detect_installed_python_2.stdout_lines | last | d('') == ''
      changed_when: False

    when: detect_installed_python.rc | d(1) == 41

  - name: set ansible_python_interpreter
    set_fact:
      ansible_python_interpreter: "{{ ( (detect_installed_python.rc | d(1) == 0)
                                      | ternary(detect_installed_python, detect_installed_python_2) ).stdout_lines | last }}"
    when: "{{ ( (detect_installed_python.rc | d(1) == 0)
              | ternary(detect_installed_python, detect_installed_python_2) ).stdout_lines | last != '/usr/bin/python' }}"

  vars:
  - shell_exec: >-
        {{ ( [ansible_shell_type | d('sh')]
             | intersect(['sh', 'csh', 'fish'])
             | list
             | length == 1
             and ansible_version.full | version_compare('2.1', '>='))
           | ternary(ansible_shell_executable, '/bin/sh')
        }}
  - shell_type: >-
        {{ ( [ansible_shell_type | d('')]
             | intersect(['sh', 'csh', 'fish'])
             | list
             | length == 1 )
           | ternary(ansible_shell_type, 'sh')
        }}
  - shell_err_code:  "{{ (shell_type == 'sh')   | ternary('$?',     '$status') }}"
  - shell_and:       "{{ (shell_type == 'fish') | ternary('; and',  '&&')      }}"
  - shell_or:        "{{ (shell_type == 'fish') | ternary('; or',   '||')      }}"
  - shell_export:    "{{ (shell_type == 'csh')  | ternary('setenv', 'export')  }}"
  - shell_export_eq: "{{ (shell_type == 'csh')  | ternary(' ',      '=')       }}"
  - shell_exit_if_python_is_valid: >
        eval \""$PY"\"" -c 'import sys; sys.exit(not (sys.hexversion >= 0x02060000 and sys.hexversion < 0x03000000))'"
        {{ shell_and }} which "$PY"
        {{ shell_and }} exit 0
  - exxo_installer_version: "0"
  when: ansible_python_interpreter is not defined

- name: test ping
  ping:
{'fraction_non_alphanumeric': 0.15134187955362907, 'fraction_numerical': 0.011989301853730518, 'mean_word_length': 2.2670985236517023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '295689', 'n_tokens_mistral': 7290, 'n_tokens_neox': 6970, 'n_words': 1498}