diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..a6d8f52 --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,3 @@ +--- +skip_list: + - role-name diff --git a/README.md b/README.md index b49974f..eeb34e5 100644 --- a/README.md +++ b/README.md @@ -14,25 +14,32 @@ CentOS 7 is recommended on AWS since AWS only provides packages for it. ## Role Variables -* **xilinx_xrt_install**: If `true` install XRT. +* **xilinx_xrt_install**: If `true`, install XRT. Default to `true`. * **xilinx_xrt_version**: Xilinx XRT version to install. Default to the latest available. +* **xilinx_xrt_from_src**: If `true`, install XRT from sources instead of Xilinx provided packages. + Default to `false`. * **xilinx_xrt_env**: XRT specific environment. - Supported values: `aws`. - Default to the classical Xilinx XRT environment. + Supported values: `aws`, `azure`. + If not specified, default to the classical Xilinx XRT environment. * **xilinx_xrt_ensure_compatible_kernel**: If `true`, ensure the Linux kernel installed is compatible. Default to `true`. * **xilinx_xrt_bashrc**: If `true`, add the source of the XRT setup script to the user `~/.bashrc`. Default to `false`. +* **xilinx_xrt_container**: Set this to `true` if running the role inside a container to avoid kernel version mismatch issues. + Default to `false`. +* **xilinx_xrt_rhel7_devtoolset**: Fallback Red Hat Developer Toolset version to use on RHEL/CentOS 7 if not installed by XRT provided dependencies install script. + No effect if *xilinx_xrt_from_src* is `false`. + Default to `9`. ### AWS FPGA -The following is only available when **xilinx_xrt_env** is set to `aws`. - AWS environment support extra variables associated to [AWS FPGA](https://github.com/aws/aws-fpga). -* **aws_fpga_install**; If `true` install AWS FPGA runtime libraries. +The following is only available when **xilinx_xrt_env** is set to `aws`. + +* **aws_fpga_install**: If `true`, install AWS FPGA runtime libraries. Default to `true`. * **aws_fpga_src_install**: If specified, install AWS FPGA sources in the specified directory. Default is to not install sources. @@ -47,6 +54,7 @@ AWS environment support extra variables associated to [AWS FPGA](https://github. Default to `false`. No effect if *aws_fpga_allow_non_root* is `false`. * **aws_fpga_driver**: If specified, install the specified alternate driver. + If not specified use the default XOCL driver. This may require *xilinx_xrt_install* set to `False`. Supported values: `xdma`. diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1880ec6..50dd293 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -22,6 +22,7 @@ pool: jobs: - job: tests + timeoutInMinutes: 120 displayName: Tests variables: cacheDir: /tmp/.pipeline_cache @@ -67,9 +68,13 @@ jobs: displayName: Test Ansible role condition: always() env: - ANSIBLE_STDOUT_CALLBACK: debug + ANSIBLE_DISPLAY_SKIPPED_HOSTS: "False" ANSIBLE_FORCE_COLOR: "True" + ANSIBLE_FORKS: "30" ANSIBLE_NOCOLOR": "False" + ANSIBLE_PIPELINING: "True" + ANSIBLE_SSH_ARGS: "-o ControlMaster=auto -o ControlPersist=60s" + ANSIBLE_STDOUT_CALLBACK: debug - job: displayName: Ansible Galaxy publish diff --git a/defaults/main.yml b/defaults/main.yml index 1960a57..90f066e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,18 +2,27 @@ # Install Xilinx XRT xilinx_xrt_install: true +# Install Xilinx XRT from sources instead of packages +xilinx_xrt_from_src: false + # Add "source /opt/xilinx/xrt/setup.sh" to user "~/.bashrc" xilinx_xrt_bashrc: false # Xilinx XRT environement, default to Xilinx classical environement -xilinx_xrt_env: '' +_xilinx_xrt_env: "{{ xilinx_xrt_env | default('') }}" # Xilinx XRT version to install (Default to latest available -xilinx_xrt_version: "{{ xilinx_xrt_env | xrt_latest(ansible_facts)}}" +xilinx_xrt_version: "{{ _xilinx_xrt_env | xrt_latest(ansible_facts) }}" # Linux kernel version compatibles with XRT xilinx_xrt_ensure_compatible_kernel: true +# Run inside a container +xilinx_xrt_container: false + +# Red Hat Developer Toolset CentOS 7 fallback version +xilinx_xrt_rhel7_devtoolset: 9 + # If true and xilinx_xrt_env is "aws", install AWS FPGA runtimes aws_fpga_install: true @@ -26,11 +35,11 @@ aws_fpga_sdk_override_group: false # ------------------- xrt_package: "{{ xilinx_xrt_version | - xrt_pkg_name('xrt', xilinx_xrt_env, ansible_facts)}}" + xrt_pkg_name('xrt', _xilinx_xrt_env, ansible_facts)}}" xrt_source: "{{ xilinx_xrt_version | - xrt_pkg_src('xrt', xilinx_xrt_env, ansible_facts)}}" + xrt_pkg_src('xrt', _xilinx_xrt_env, ansible_facts)}}" -aws_package: "{{ xilinx_xrt_version | - xrt_pkg_name('aws', xilinx_xrt_env, ansible_facts)}}" -aws_source: "{{ xilinx_xrt_version | - xrt_pkg_src('aws', xilinx_xrt_env, ansible_facts)}}" +env_package: "{{ xilinx_xrt_version | + xrt_pkg_name(_xilinx_xrt_env, _xilinx_xrt_env, ansible_facts)}}" +env_source: "{{ xilinx_xrt_version | + xrt_pkg_src(_xilinx_xrt_env, _xilinx_xrt_env, ansible_facts)}}" diff --git a/filter_plugins/main.py b/filter_plugins/main.py index 3e909ae..d60739e 100644 --- a/filter_plugins/main.py +++ b/filter_plugins/main.py @@ -133,7 +133,15 @@ "2018.2": "3.10.0-957", } }, - "Debian": {"bionic": {"2018.3": "4.18.0", "2018.2": "4.18.0"}}, + "Debian": { + "bionic": { + "2018.3": "4.18.0", + "2018.2": "4.18.0", + "2019.1": "4.18.0", + "2019.2": "4.18.0", + "2020.1": "4.18.0", + } + }, } @@ -277,11 +285,59 @@ def xrt_kernel(version, ansible_facts): """ family, dist = _os_release(ansible_facts) try: - return _MAX_KERNEL[family][dist][version] + return _MAX_KERNEL[family][dist][str(version)] except KeyError: return "" +def xrt_find_package_path(packages, name): + """ + Get package path from a list of package from "ansible.builtin.find". + + Args: + packages (list of dict): XRT packages list. + name (str): Package name: 'xrt' or 'aws'. + + Returns: + str: Package path. + """ + filtered = tuple( + package["path"] + for package in packages + if package["path"].rsplit(".", 1)[0].endswith("-" + name) + ) + try: + return filtered[0] + except IndexError: + raise ValueError( + 'No package found for "%s" in %s' + % (name, ", ".join(package["path"] for package in packages)) + ) + + +def xrt_find_devtoolset(ansible_facts): + """ + Get the latest installed Red Hat Developer Toolset from installed package. + + Args: + ansible_facts (dict): Ansible facts. + + Returns: + str: Package path. + """ + import re + + devtoolset_match = re.compile(r"^devtoolset-\d+$").match + filtered = sorted( + (package for package in ansible_facts["packages"] if devtoolset_match(package)), + key=lambda k: int(k.rsplit("-", 1)[1]), + ) + try: + return filtered[-1] + except IndexError: + raise ValueError('No "devtoolset-*" package installed') + + class FilterModule(object): """Return filter plugin""" @@ -293,4 +349,6 @@ def filters(): "xrt_pkg_name": xrt_pkg_name, "xrt_pkg_src": xrt_pkg_src, "xrt_latest": xrt_latest, + "xrt_find_package_path": xrt_find_package_path, + "xrt_find_devtoolset": xrt_find_devtoolset, } diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 5e2d7fe..9022376 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -1,8 +1,8 @@ --- - name: Converge hosts: all + strategy: free roles: - role: ansible-role-xilinx_xrt vars: - xilinx_xrt_ensure_compatible_kernel: false - reboot_on_kernel_update: false + xilinx_xrt_container: true diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index aaef091..189bdba 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -27,6 +27,12 @@ platforms: groups: - xrt_2019_2 + - name: ubuntu_bionic-2019.2-src + image: ubuntu:bionic + groups: + - xrt_2019_2 + - xrt_src + - name: ubuntu_bionic-2019.1 image: ubuntu:bionic groups: @@ -80,6 +86,12 @@ platforms: groups: - xrt_2021_1 + - name: centos_7-2021.1-src + image: centos:7 + groups: + - xrt_2021_1 + - xrt_src + - name: centos_7-2020.1 image: centos:7 groups: @@ -136,6 +148,8 @@ provisioner: xilinx_xrt_version: 2018.3 xrt_2018_2: xilinx_xrt_version: 2018.2 + xrt_src: + xilinx_xrt_from_src: true no_xrt: xilinx_xrt_install: false aws: @@ -146,3 +160,11 @@ provisioner: verifier: name: testinfra + +scenario: + test_sequence: + - dependency + - create + - converge + - idempotence + - verify diff --git a/tasks/aws.yml b/tasks/aws.yml deleted file mode 100644 index 3d0ae4e..0000000 --- a/tasks/aws.yml +++ /dev/null @@ -1,199 +0,0 @@ ---- - -- name: Download XRT AWS package - get_url: - url: "{{ aws_source }}" - dest: "{{ xrt_tmp.path }}/{{ aws_package }}" - retries: 10 - delay: 1 - register: _xrt_aws - until: _xrt_aws is successful - when: - - xilinx_xrt_install | bool - - not xbutil.stat.exists - -- name: Download XRT AWS package signature - get_url: - url: "{{ aws_source }}.sig" - dest: "{{ xrt_tmp.path }}/{{ aws_package }}.sig" - failed_when: false # May be not available - register: aws_package_sig - when: - - xilinx_xrt_install | bool - - not xbutil.stat.exists - - xrt_package_sig.state is defined - -- name: Verify XRT AWS package signature - command: "gpg --verify {{ aws_package }}.sig {{ aws_package }}" - args: - chdir: "{{ xrt_tmp.path }}" - changed_when: false - when: - - xilinx_xrt_install | bool - - not xbutil.stat.exists - - aws_package_sig.state is defined - -- name: Download XRT AWS package checksum - get_url: - url: "{{ aws_source }}.digests" - dest: "{{ xrt_tmp.path }}/{{ aws_package }}.digests" - failed_when: false # May be not available - register: aws_package_digests - when: - - xilinx_xrt_install | bool - - not xbutil.stat.exists - - aws_package_sig.state is not defined - - xrt_package_digests.state is defined - -- name: Verify XRT AWS package checksum - command: sha512sum -c {{ xrt_package }}.digests - args: - chdir: "{{ xrt_tmp.path }}" - changed_when: false - when: - - xilinx_xrt_install | bool - - not xbutil.stat.exists - - aws_package_digests.state is defined - -- name: Ensure AWS XRT DEB package is installed - package: - deb: "{{ xrt_tmp.path }}/{{ aws_package }}" - state: present - install_recommends: false - retries: 10 - delay: 1 - register: _xrt_aws_deb - until: _xrt_aws_deb is successful - when: - - xilinx_xrt_install | bool - - ansible_os_family == 'Debian' - - not xbutil.stat.exists - -- name: Ensure AWS XRT RPM package is installed - yum: - name: "{{ xrt_tmp.path }}/{{ aws_package }}" - state: present - install_weak_deps: false - disable_gpg_check: true - retries: 10 - delay: 1 - register: _xrt_aws_rpm - until: _xrt_aws_rpm is successful - when: - - xilinx_xrt_install | bool - - ansible_os_family == 'RedHat' - - not xbutil.stat.exists - -- name: Get "/usr/local/lib64" directory information - stat: - path: /usr/local/lib64 - register: usr_local_lib64 - when: aws_fpga_install | bool - -- name: Get "libfpga_mgmt.so" file information - stat: - path: "/usr/local/{{ usr_local_lib64.stat.exists | - ternary('lib64','lib') }}/libfpga_mgmt.so" - register: libfpga_mgmt - when: aws_fpga_install | bool - -- name: Create AWS temporary directory - tempfile: - state: directory - prefix: aws_ - register: aws_tmp - when: - - aws_fpga_install | bool - - aws_fpga_src_install is not defined - - not libfpga_mgmt.stat.exists - notify: Clean up AWS temporary directory - -- name: Set AWS FPGA source directory - set_fact: - aws_fpga_src: "{{ aws_tmp.path }}" - when: - - aws_fpga_install | bool - - aws_fpga_src_install is not defined - - not libfpga_mgmt.stat.exists - -- name: Set AWS FPGA source directory - set_fact: - aws_fpga_src: "{{ aws_fpga_src_install }}" - when: aws_fpga_src_install is defined - -- name: Ensure AWS FPGA source directory exists - file: - state: directory - path: "{{ aws_fpga_src }}" - when: "aws_fpga_src_install is defined or ( - aws_fpga_install | bool and not libfpga_mgmt.stat.exists)" - -- name: Download and extract AWS FPGA release tarbal - unarchive: - src: "https://api.github.com/repos/aws/aws-fpga/tarball/\ - {{ aws_fpga_version | default('') }}" - dest: "{{ aws_fpga_src }}" - remote_src: true - extra_opts: ['--strip-components=1'] - retries: 10 - delay: 1 - register: _aws_fpga_tar - until: _aws_fpga_tar is successful - when: "aws_fpga_src_install is defined or ( - aws_fpga_install | bool and not libfpga_mgmt.stat.exists)" - -- name: Ensure AWS FPGA build dependencies are present - apt: - name: - - gcc - - libc-dev - - make - - pciutils - state: present - install_recommends: false - retries: 10 - delay: 1 - register: _aws_fpga_deb_deps - until: _aws_fpga_deb_deps is successful - when: - - aws_fpga_install | bool - - ansible_os_family == 'Debian' - - not libfpga_mgmt.stat.exists - -- name: Ensure AWS FPGA build dependencies are present - yum: - name: - - gcc - - make - - pciutils - state: present - install_weak_deps: false - retries: 10 - delay: 1 - register: _aws_fpga_rpm_deps - until: _aws_fpga_rpm_deps is successful - when: - - aws_fpga_install | bool - - ansible_os_family == 'RedHat' - - not libfpga_mgmt.stat.exists - -- name: Build and install AWS FPGA libraries and utilities - shell: "source {{ aws_fpga_src }}/sdk_setup.sh;" - environment: - AWS_FPGA_ALLOW_NON_ROOT: "{{ aws_fpga_allow_non_root or '' }}" - AWS_FPGA_SDK_GROUP: "{{ aws_fpga_sdk_group }}" - AWS_FPGA_SDK_OVERRIDE_GROUP: "{{ aws_fpga_sdk_override_group or '' }}" - args: - creates: "/usr/local/{{ usr_local_lib64.stat.exists | - ternary('lib64','lib') }}/libfpga_mgmt.so" - executable: /bin/bash - when: - - aws_fpga_install | bool - - not libfpga_mgmt.stat.exists - -- name: Install AWS FPGA alternate driver - command: "make -C {{ aws_fpga_src }}/sdk/linux_kernel_drivers/{{ aws_fpga_driver }} install" - changed_when: false - when: - - aws_fpga_driver is defined - - aws_fpga_install | bool diff --git a/tasks/aws_fpga_from_src.yml b/tasks/aws_fpga_from_src.yml new file mode 100644 index 0000000..feeb7cd --- /dev/null +++ b/tasks/aws_fpga_from_src.yml @@ -0,0 +1,104 @@ +--- + +- name: Get "/usr/local/lib64" directory information + stat: + path: /usr/local/lib64 + register: usr_local_lib64 + +- name: Get "libfpga_mgmt.so" file information + stat: + path: "/usr/local/{{ usr_local_lib64.stat.exists | + ternary('lib64','lib') }}/libfpga_mgmt.so" + register: libfpga_mgmt + +- name: Create AWS temporary directory + tempfile: + state: directory + prefix: aws_ + register: aws_tmp + when: + - aws_fpga_src_install is not defined + - not libfpga_mgmt.stat.exists + notify: Clean up AWS temporary directory + +- name: Set AWS FPGA source directory + set_fact: + aws_fpga_src: "{{ aws_tmp.path }}" + when: + - aws_fpga_src_install is not defined + - not libfpga_mgmt.stat.exists + +- name: Set AWS FPGA source directory + set_fact: + aws_fpga_src: "{{ aws_fpga_src_install }}" + when: aws_fpga_src_install is defined + +- name: Ensure AWS FPGA source directory exists + file: + state: directory + path: "{{ aws_fpga_src }}" + mode: 0644 + when: aws_fpga_src_install is defined + +- name: Download and extract AWS FPGA release tarbal + unarchive: + src: "https://api.github.com/repos/aws/aws-fpga/tarball/\ + {{ aws_fpga_version | default('') }}" + dest: "{{ aws_fpga_src }}" + remote_src: true + extra_opts: ['--strip-components=1'] + retries: 10 + delay: 1 + register: _aws_fpga_tar + until: _aws_fpga_tar is successful + when: aws_fpga_src_install is defined or not libfpga_mgmt.stat.exists + +- name: Ensure AWS FPGA build dependencies are present + apt: + name: + - gcc + - libc-dev + - make + - pciutils + state: present + install_recommends: false + retries: 10 + delay: 1 + register: _aws_fpga_deb_deps + until: _aws_fpga_deb_deps is successful + when: + - ansible_os_family == 'Debian' + - not libfpga_mgmt.stat.exists + +- name: Ensure AWS FPGA build dependencies are present + yum: + name: + - gcc + - make + - pciutils + state: present + install_weak_deps: false + retries: 10 + delay: 1 + register: _aws_fpga_rpm_deps + until: _aws_fpga_rpm_deps is successful + when: + - ansible_os_family == 'RedHat' + - not libfpga_mgmt.stat.exists + +- name: Build and install AWS FPGA libraries and utilities + shell: "source {{ aws_fpga_src }}/sdk_setup.sh;" + environment: + AWS_FPGA_ALLOW_NON_ROOT: "{{ aws_fpga_allow_non_root or '' }}" + AWS_FPGA_SDK_GROUP: "{{ aws_fpga_sdk_group }}" + AWS_FPGA_SDK_OVERRIDE_GROUP: "{{ aws_fpga_sdk_override_group or '' }}" + args: + creates: "/usr/local/{{ usr_local_lib64.stat.exists | + ternary('lib64','lib') }}/libfpga_mgmt.so" + executable: /bin/bash + when: not libfpga_mgmt.stat.exists + +- name: Install AWS FPGA alternate driver + command: "make -C {{ aws_fpga_src }}/sdk/linux_kernel_drivers/{{ aws_fpga_driver }} install" + changed_when: false + when: aws_fpga_driver is defined diff --git a/tasks/main.yml b/tasks/main.yml index 6adf74b..7b1675d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,6 +8,7 @@ when: - xilinx_xrt_ensure_compatible_kernel | bool - xilinx_xrt_install | bool + - not (xilinx_xrt_container | bool) - name: Get "xbutil" file information stat: @@ -25,255 +26,157 @@ - xilinx_xrt_install | bool - not xbutil.stat.exists -- name: Download XRT package - get_url: - url: "{{ xrt_source }}" - dest: "{{ xrt_tmp.path }}/{{ xrt_package }}" +- name: Ensure APT cache is up to date + apt: + update_cache: true + changed_when: false retries: 10 delay: 1 - register: _xrt - until: _xrt is successful - notify: Ensure Xilinx Management Proxy Daemon is started and enabled at boot - when: - - xilinx_xrt_install | bool - - not xbutil.stat.exists - -- name: Download XRT package signature - get_url: - url: "{{ xrt_source }}.sig" - dest: "{{ xrt_tmp.path }}/{{ xrt_package }}.sig" - failed_when: false # May be not available - register: xrt_package_sig - when: - - xilinx_xrt_install | bool - - not xbutil.stat.exists + register: _apt_cache + until: _apt_cache is successful + when: ansible_os_family == 'Debian' -- name: Ensure GPG is installed - package: - name: gnupg +- name: Ensure pyopencl package is installed on Ubuntu 18.04 to avoid XRT install failure + apt: + name: python-pyopencl state: present + install_recommends: false retries: 10 delay: 1 - register: _gpg - until: _gpg is successful - when: - - xilinx_xrt_install | bool - - not xbutil.stat.exists - - xrt_package_sig.state is defined - -- name: Download Xilinx master signing key - get_url: - url: "https://www.xilinx.com/support/download/xilinx-master-signing-key.asc" - dest: "{{ xrt_tmp.path }}/xilinx-master-signing-key.asc" - retries: 10 - delay: 1 - register: _xilinx_key - until: _xilinx_key is successful - when: - - xilinx_xrt_install | bool - - not xbutil.stat.exists - - xrt_package_sig.state is defined - -- name: Ensure Xilinx master signing key is imported in GPG - command: "gpg --import {{ xrt_tmp.path }}/xilinx-master-signing-key.asc" - when: - - xilinx_xrt_install | bool - - not xbutil.stat.exists - - xrt_package_sig.state is defined - -- name: Verify XRT package signature - command: "gpg --verify {{ xrt_package }}.sig {{ xrt_package }}" - args: - chdir: "{{ xrt_tmp.path }}" - changed_when: false + register: _pyopencl + until: _pyopencl is successful when: - xilinx_xrt_install | bool + - ansible_distribution == 'Ubuntu' + - ansible_distribution_release == 'bionic' - not xbutil.stat.exists - - xrt_package_sig.state is defined -- name: Download XRT package checksum - get_url: - url: "{{ xrt_source }}.digests" - dest: "{{ xrt_tmp.path }}/{{ xrt_package }}.digests" - failed_when: false # May be not available - register: xrt_package_digests +- include_tasks: xrt_from_pkg.yml when: - xilinx_xrt_install | bool + - not (xilinx_xrt_from_src | bool) - not xbutil.stat.exists - - xrt_package_sig.state is not defined -- name: Verify XRT package checksum - command: sha512sum -c {{ xrt_package }}.digests - args: - chdir: "{{ xrt_tmp.path }}" - changed_when: false +- include_tasks: xrt_from_src.yml when: - xilinx_xrt_install | bool + - xilinx_xrt_from_src | bool - not xbutil.stat.exists - - xrt_package_digests.state is defined -- name: Ensure EPEL repository is installed +- name: Ensure XRT RPM package is installed yum: - name: "https://dl.fedoraproject.org/pub/epel/\ - epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm" + name: "{{ xrt_package_path }}" state: present install_weak_deps: false disable_gpg_check: true retries: 10 delay: 1 - register: _epel - until: _epel is successful + register: _xrt_rpm + until: _xrt_rpm is successful when: - xilinx_xrt_install | bool - - not xbutil.stat.exists - ansible_os_family == 'RedHat' - - ansible_distribution_major_version in ("7", "8") - -- name: Ensure RHEL optional RPMs repository is enabled - command: - cmd: subscription-manager repos --enable "rhel-7-server-optional-rpms" - args: - warn: false - changed_when: false - when: - - ansible_distribution == "Red Hat Enterprise Linux" - - ansible_distribution_major_version == "7" - -- name: Ensure CodeReady Linux Builder repository is enabled - command: - cmd: subscription-manager repos --enable "codeready-builder-for-rhel-8-x86_64-rpms" - args: - warn: false - changed_when: false - when: - - ansible_distribution == "Red Hat Enterprise Linux" - - ansible_distribution_major_version == "8" + - not xbutil.stat.exists -- name: Ensure DNF core plugins are installed - dnf: +- name: Ensure XRT DEB package is installed + apt: + deb: "{{ xrt_package_path }}" state: present - name: python3-dnf-plugins-core - install_weak_deps: false + install_recommends: false retries: 10 delay: 1 - register: _dnf_plugins - until: _dnf_plugins is successful + register: xrt_deb + until: xrt_deb is successful when: - - ansible_distribution == "CentOS" - - ansible_distribution_major_version == "8" + - xilinx_xrt_install | bool + - ansible_os_family == 'Debian' + - not xbutil.stat.exists -- name: Ensure Powertools repository is enabled - command: - cmd: dnf config-manager --set-enabled powertools - args: - warn: false - changed_when: false - when: - - ansible_distribution == "CentOS" - - ansible_distribution_major_version == "8" +- block: + - name: Verify that XOCL kernel module is properly installed + command: lsmod + register: _lsmod + failed_when: not "xocl" in _lsmod.stdout + changed_when: false -- name: Ensure AppStream repository is enabled - command: - cmd: dnf config-manager --set-enabled appstream - args: - warn: false - changed_when: false - when: - - ansible_distribution == "CentOS" - - ansible_distribution_major_version == "8" + rescue: + - name: Show XRT DEB install log + debug: + msg: "{{ xrt_deb.stdout }}" + + - name: Get DKMS make log + shell: cat /var/lib/dkms/xrt/*/build/make.log + register: dkms_log + changed_when: false + + - name: Show DKMS make log + debug: + msg: "{{ dkms_log.stdout }}" + + - name: Fail on XOCL kernel module installation failure + fail: + msg: The XOCL driver is not properly installed. -- name: Ensure Kernel headers RPM are installed - yum: - name: - - "kernel-devel-{{ ansible_kernel }}" - - "kernel-headers-{{ ansible_kernel }}" - state: present - install_weak_deps: false - enablerepo: C7.* - retries: 10 - delay: 1 - register: _kernel_rpm - until: _kernel_rpm is successful when: + - not (xilinx_xrt_container | bool) - xilinx_xrt_install | bool - not xbutil.stat.exists - - ansible_os_family == 'RedHat' - tags: - - molecule-notest # Bad detected kernel version from container -- name: Ensure XRT RPM package is installed - yum: - name: "{{ xrt_tmp.path }}/{{ xrt_package }}" - state: present - install_weak_deps: false - disable_gpg_check: true - retries: 10 - delay: 1 - register: _xrt_rpm - until: _xrt_rpm is successful +- name: Ensure XRT is sourced in ~/.bashrc + lineinfile: + path: /home/{{ ansible_user }}/.bashrc + regexp: "^source /opt/xilinx/xrt/setup.sh" + line: source /opt/xilinx/xrt/setup.sh when: - xilinx_xrt_install | bool - - ansible_os_family == 'RedHat' - - not xbutil.stat.exists + - xilinx_xrt_bashrc | bool -- name: Ensure APT cache is up to date - apt: - update_cache: true - changed_when: false - retries: 10 - delay: 1 - register: _apt_cache - until: _apt_cache is successful +- include_tasks: xrt_env_from_pkg.yml when: + - xilinx_xrt_env is defined - xilinx_xrt_install | bool - - ansible_os_family == 'Debian' + - not (xilinx_xrt_from_src | bool) - not xbutil.stat.exists -- block: - - name: Ensure Kernel headers DEB are installed - apt: - name: "linux-headers-{{ ansible_kernel }}" - retries: 10 - delay: 1 - register: _kernel_deb - until: _kernel_deb is successful - rescue: - - name: Ensure Kernel headers DEB are installed - apt: - name: "linux-headers-{{ ansible_kernel }}-generic" - retries: 10 - delay: 1 - register: _kernel_deb - until: _kernel_deb is successful +- include_tasks: xrt_env_from_src.yml when: + - xilinx_xrt_env is defined - xilinx_xrt_install | bool - - ansible_os_family == 'Debian' + - xilinx_xrt_from_src | bool - not xbutil.stat.exists - tags: - - molecule-notest # Bad detected kernel version from container -- name: Ensure XRT DEB package is installed +- name: Ensure environment specific XRT package is installed package: - deb: "{{ xrt_tmp.path }}/{{ xrt_package }}" + deb: "{{ env_package_path }}" state: present install_recommends: false retries: 10 delay: 1 - register: _xrt_deb - until: _xrt_deb is successful + register: _xrt_env_deb + until: _xrt_env_deb is successful when: + - xilinx_xrt_env is defined - xilinx_xrt_install | bool - - ansible_os_family == 'Debian' - not xbutil.stat.exists + - ansible_os_family == 'Debian' -- name: Ensure XRT is sourced in ~/.bashrc - lineinfile: - path: /home/{{ ansible_user }}/.bashrc - regexp: "^source /opt/xilinx/xrt/setup.sh" - line: source /opt/xilinx/xrt/setup.sh +- name: Ensure environment specific XRT package is installed + yum: + name: "{{ env_package_path }}" + state: present + install_weak_deps: false + disable_gpg_check: true + retries: 10 + delay: 1 + register: _xrt_env_rpm + until: _xrt_env_rpm is successful when: + - xilinx_xrt_env is defined - xilinx_xrt_install | bool - - xilinx_xrt_bashrc | bool + - not xbutil.stat.exists + - ansible_os_family == 'RedHat' -- include_tasks: aws.yml - when: xilinx_xrt_env == 'aws' +- include_tasks: aws_fpga_from_src.yml + when: + - _xilinx_xrt_env == "aws" + - aws_fpga_install | bool diff --git a/tasks/xrt_env_from_pkg.yml b/tasks/xrt_env_from_pkg.yml new file mode 100644 index 0000000..5a55d94 --- /dev/null +++ b/tasks/xrt_env_from_pkg.yml @@ -0,0 +1,46 @@ +--- + +- name: Set XRT environment specific package path + set_fact: + env_package_path: "{{ xrt_tmp.path }}/{{ env_package }}" + +- name: Download XRT environment specific package + get_url: + url: "{{ env_source }}" + dest: "{{ env_package_path }}" + retries: 10 + delay: 1 + register: _xrt_env + until: _xrt_env is successful + +- name: Download XRT environment specific package signature + get_url: + url: "{{ env_source }}.sig" + dest: "{{ env_package_path }}.sig" + failed_when: false # May be not available + register: env_package_sig + when: xrt_package_sig.state is defined + +- name: Verify XRT environment specific package signature + command: "gpg --verify {{ env_package }}.sig {{ env_package }}" + args: + chdir: "{{ xrt_tmp.path }}" + changed_when: false + when: env_package_sig.state is defined + +- name: Download XRT environment specific package checksum + get_url: + url: "{{ env_source }}.digests" + dest: "{{ env_package_path }}.digests" + failed_when: false # May be not available + register: env_package_digests + when: + - env_package_sig.state is not defined + - xrt_package_digests.state is defined + +- name: Verify XRT environment specific package checksum + command: sha512sum -c {{ xrt_package }}.digests + args: + chdir: "{{ xrt_tmp.path }}" + changed_when: false + when: env_package_digests.state is defined diff --git a/tasks/xrt_env_from_src.yml b/tasks/xrt_env_from_src.yml new file mode 100644 index 0000000..69cb4b4 --- /dev/null +++ b/tasks/xrt_env_from_src.yml @@ -0,0 +1,5 @@ +--- + +- name: Set XRT environment specific package path + set_fact: + env_package_path: "{{ xrt_packages_list.files | xrt_find_package_path(xilinx_xrt_env) }}" diff --git a/tasks/xrt_from_pkg.yml b/tasks/xrt_from_pkg.yml new file mode 100644 index 0000000..8f022f8 --- /dev/null +++ b/tasks/xrt_from_pkg.yml @@ -0,0 +1,171 @@ +--- +- name: Set XRT package path + set_fact: + xrt_package_path: "{{ xrt_tmp.path }}/{{ xrt_package }}" + +- name: Download XRT package + get_url: + url: "{{ xrt_source }}" + dest: "{{ xrt_package_path }}" + retries: 10 + delay: 1 + register: _xrt + until: _xrt is successful + notify: Ensure Xilinx Management Proxy Daemon is started and enabled at boot + +- name: Download XRT package signature + get_url: + url: "{{ xrt_source }}.sig" + dest: "{{ xrt_package_path }}.sig" + failed_when: false # May be not available + register: xrt_package_sig + +- name: Ensure GPG is installed + package: + name: gnupg + state: present + retries: 10 + delay: 1 + register: _gpg + until: _gpg is successful + when: xrt_package_sig.state is defined + +- name: Download Xilinx master signing key + get_url: + url: "https://www.xilinx.com/support/download/xilinx-master-signing-key.asc" + dest: "{{ xrt_tmp.path }}/xilinx-master-signing-key.asc" + retries: 10 + delay: 1 + register: _xilinx_key + until: _xilinx_key is successful + when: xrt_package_sig.state is defined + +- name: Ensure Xilinx master signing key is imported in GPG + command: "gpg --import {{ xrt_tmp.path }}/xilinx-master-signing-key.asc" + when: xrt_package_sig.state is defined + +- name: Verify XRT package signature + command: "gpg --verify {{ xrt_package }}.sig {{ xrt_package }}" + args: + chdir: "{{ xrt_tmp.path }}" + changed_when: false + when: xrt_package_sig.state is defined + +- name: Download XRT package checksum + get_url: + url: "{{ xrt_source }}.digests" + dest: "{{ xrt_package_path }}.digests" + failed_when: false # May be not available + register: xrt_package_digests + when: xrt_package_sig.state is not defined + +- name: Verify XRT package checksum + command: sha512sum -c {{ xrt_package }}.digests + args: + chdir: "{{ xrt_tmp.path }}" + changed_when: false + when: xrt_package_digests.state is defined + +- name: Ensure EPEL repository is installed + yum: + name: "https://dl.fedoraproject.org/pub/epel/\ + epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm" + state: present + install_weak_deps: false + disable_gpg_check: true + retries: 10 + delay: 1 + register: _epel + until: _epel is successful + when: + - ansible_os_family == 'RedHat' + - ansible_distribution_major_version in ("7", "8") + +- name: Ensure RHEL optional RPMs repository is enabled + command: + cmd: subscription-manager repos --enable "rhel-7-server-optional-rpms" + args: + warn: false + changed_when: false + when: + - ansible_distribution == "Red Hat Enterprise Linux" + - ansible_distribution_major_version == "7" + +- name: Ensure CodeReady Linux Builder repository is enabled + command: + cmd: subscription-manager repos --enable "codeready-builder-for-rhel-8-x86_64-rpms" + args: + warn: false + changed_when: false + when: + - ansible_distribution == "Red Hat Enterprise Linux" + - ansible_distribution_major_version == "8" + +- name: Ensure DNF core plugins are installed + dnf: + state: present + name: python3-dnf-plugins-core + install_weak_deps: false + retries: 10 + delay: 1 + register: _dnf_plugins + until: _dnf_plugins is successful + when: + - ansible_distribution == "CentOS" + - ansible_distribution_major_version == "8" + +- name: Ensure Powertools repository is enabled + command: + cmd: dnf config-manager --set-enabled powertools + args: + warn: false + changed_when: false + when: + - ansible_distribution == "CentOS" + - ansible_distribution_major_version == "8" + +- name: Ensure AppStream repository is enabled + command: + cmd: dnf config-manager --set-enabled appstream + args: + warn: false + changed_when: false + when: + - ansible_distribution == "CentOS" + - ansible_distribution_major_version == "8" + +- name: Ensure Kernel headers RPM are installed + yum: + name: + - "kernel-devel-{{ ansible_kernel }}" + - "kernel-headers-{{ ansible_kernel }}" + state: present + install_weak_deps: false + enablerepo: C7.* + retries: 10 + delay: 1 + register: _kernel_rpm + until: _kernel_rpm is successful + when: + - ansible_os_family == 'RedHat' + - not (xilinx_xrt_container | bool) + +- block: + - name: Ensure Kernel headers DEB are installed + apt: + name: "linux-headers-{{ ansible_kernel }}" + retries: 10 + delay: 1 + register: _kernel_deb + until: _kernel_deb is successful + rescue: + - name: Ensure Kernel headers DEB are installed + apt: + name: "linux-headers-{{ ansible_kernel }}-generic" + retries: 10 + delay: 1 + register: _kernel_deb + until: _kernel_deb is successful + when: + - ansible_os_family == 'Debian' + - not (xilinx_xrt_container | bool) diff --git a/tasks/xrt_from_src.yml b/tasks/xrt_from_src.yml new file mode 100644 index 0000000..a64d5b1 --- /dev/null +++ b/tasks/xrt_from_src.yml @@ -0,0 +1,98 @@ +--- + +- name: Download and extract XRT release tarbal + unarchive: + src: "https://api.github.com/repos/Xilinx/XRT/tarball/\ + {{ xilinx_xrt_version | default('') }}" + dest: "{{ xrt_tmp.path }}" + remote_src: true + extra_opts: ['--strip-components=1'] + retries: 10 + delay: 1 + register: _xrt_tar + until: _xrt_tar is successful + +- name: Ensure tzdata is installed to avoid interactive prompt + apt: + name: tzdata + state: present + install_recommends: false + retries: 10 + delay: 1 + register: _tzdata + until: _tzdata is successful + when: ansible_os_family == 'Debian' + +- name: Ensure XRT build dependencies are installed + command: "{{ xrt_tmp.path }}/src/runtime_src/tools/scripts/xrtdeps.sh\ + {{ xilinx_xrt_container | ternary(' -docker', '') }}" + changed_when: false + retries: 10 + delay: 1 + register: _xrt_deps + until: _xrt_deps is successful + +- name: Set XRT build command + set_fact: + xrt_build_command: ./build.sh + when: ansible_distribution_major_version != "7" + +- name: Gather installed packages list + package_facts: + manager: rpm + when: + - ansible_os_family == 'RedHat' + - ansible_distribution_major_version == "7" + +- block: + - name: Set XRT build command using detected Red Hat Developer Toolset + set_fact: + xrt_build_command: "scl enable {{ ansible_facts | xrt_find_devtoolset() }} ./build.sh" + rescue: + - name: Ensure Software Collections repository is installed + yum: + name: centos-release-scl + state: present + install_weak_deps: false + disable_gpg_check: true + retries: 10 + delay: 1 + register: _scl + until: _scl is successful + when: + - ansible_distribution == "CentOS" + + - name: Ensure Red Hat Developer Toolset {{ xilinx_xrt_rhel7_devtoolset }} is installed + yum: + name: "devtoolset-{{ xilinx_xrt_rhel7_devtoolset }}" + state: present + install_weak_deps: false + disable_gpg_check: true + retries: 10 + delay: 1 + register: _devtoolset + until: _devtoolset is successful + + - name: Set XRT build command using Red Hat Developer Toolset {{ xilinx_xrt_rhel7_devtoolset }} + set_fact: + xrt_build_command: "scl enable devtoolset-{{ xilinx_xrt_rhel7_devtoolset }} ./build.sh" + when: + - ansible_os_family == 'RedHat' + - ansible_distribution_major_version == "7" + +- name: Ensure XRT is built + command: "{{ xrt_build_command }}" + args: + chdir: "{{ xrt_tmp.path }}/build" + changed_when: false + +- name: Find XRT packages + find: + paths: "{{ xrt_tmp.path }}/build/Release" + file_type: file + patterns: "*.{{ (ansible_os_family == 'RedHat') | ternary('rpm', 'deb') }}" + register: xrt_packages_list + +- name: Set XRT package path + set_fact: + xrt_package_path: "{{ xrt_packages_list.files | xrt_find_package_path('xrt') }}"