|
| 1 | +--- |
| 2 | +# ------------------------- Install build dependencies ------------------------- |
| 3 | +- name: Register the list of installed packages before building nbdkit plugin |
| 4 | + yum: |
| 5 | + list: installed |
| 6 | + register: pkgs_before_builddeps |
| 7 | + |
| 8 | +- name: Install build dependencies |
| 9 | + yum: |
| 10 | + state: present |
| 11 | + name: "{{ item }}" |
| 12 | + with_items: |
| 13 | + - gcc |
| 14 | + - make |
| 15 | + - rpm-build |
| 16 | + - yum-utils |
| 17 | + - nbdkit-devel |
| 18 | + |
| 19 | +- name: Ensure gnutls-devel is installed when on CentOS |
| 20 | + yum: |
| 21 | + name: gnutls-devel |
| 22 | + state: present |
| 23 | + when: ansible_distribution == "CentOS" |
| 24 | + |
| 25 | +- name: Register the list of installed packages after building nbdkit plugin |
| 26 | + yum: |
| 27 | + list: installed |
| 28 | + register: pkgs_after_builddeps |
| 29 | + |
| 30 | +# ------------------ Create the build dir and get the source ------------------- |
| 31 | +- name: Clean the build directory |
| 32 | + file: |
| 33 | + path: "{{ v2v_build_dir }}" |
| 34 | + state: absent |
| 35 | + |
| 36 | +- name: Create the build directory |
| 37 | + file: |
| 38 | + path: "{{ v2v_build_dir }}" |
| 39 | + state: directory |
| 40 | + mode: 0700 |
| 41 | + |
| 42 | +- include_tasks: "nbdkit-source-{{ ansible_distribution | lower }}.yml" |
| 43 | + |
| 44 | +# --------------- Adjust the spec file to match the environment ---------------- |
| 45 | +- name: Locate the spec file |
| 46 | + find: |
| 47 | + paths: "{{ v2v_build_dir }}" |
| 48 | + patterns: "nbdkit-plugin-vddk.spec*" |
| 49 | + recurse: yes |
| 50 | + use_regex: no |
| 51 | + register: vddk_spec |
| 52 | + |
| 53 | +- assert: |
| 54 | + msg: Expected one spec file named nbdkit-plugin-vddk.spec |
| 55 | + that: |
| 56 | + - "vddk_spec.matched == 1" |
| 57 | + |
| 58 | +- name: Give the spec file known name |
| 59 | + copy: |
| 60 | + src: "{{ vddk_spec.files[0].path }}" |
| 61 | + dest: "{{ v2v_build_dir }}/nbdkit-plugin-vddk.spec" |
| 62 | + remote_src: true |
| 63 | + |
| 64 | +- name: Patch path to VDDK in spec file |
| 65 | + replace: |
| 66 | + path: "{{ v2v_build_dir }}/nbdkit-plugin-vddk.spec" |
| 67 | + regexp: '^(%global vddkdir) .*$' |
| 68 | + replace: "\\1 {{ v2v_vddk_install_dir }}/vmware-vix-disklib-distrib" |
| 69 | + backup: yes |
| 70 | + |
| 71 | +# -------------------- Build and install the nbdkit plugin --------------------- |
| 72 | +- name: Build RPM |
| 73 | + command: > |
| 74 | + rpmbuild -ba |
| 75 | + --define "_topdir {{ v2v_build_dir|quote }}" |
| 76 | + --define "_builddir {{ v2v_build_dir|quote }}" |
| 77 | + --define "_rpmdir {{ v2v_build_dir|quote }}" |
| 78 | + --define "_sourcedir {{ v2v_build_dir|quote }}" |
| 79 | + --define "_specdir {{ v2v_build_dir|quote }}" |
| 80 | + --define "_srcrpmdir {{ v2v_build_dir|quote }}" |
| 81 | + nbdkit-plugin-vddk.spec |
| 82 | + args: |
| 83 | + chdir: "{{ v2v_build_dir }}" |
| 84 | + creates: x86_64 |
| 85 | + |
| 86 | +- name: Find RPM |
| 87 | + find: |
| 88 | + paths: "{{ v2v_build_dir }}/x86_64" |
| 89 | + patterns: "nbdkit-plugin-vddk-[0-9]*.x86_64.rpm" |
| 90 | + recurse: no |
| 91 | + use_regex: no |
| 92 | + register: plugin_rpm |
| 93 | + |
| 94 | +- assert: |
| 95 | + msg: More than one RPM were built, expected just one |
| 96 | + that: |
| 97 | + - "plugin_rpm.matched == 1" |
| 98 | + |
| 99 | +- name: Install built RPM |
| 100 | + yum: |
| 101 | + name: "{{ plugin_rpm.files[0].path }}" |
| 102 | + state: present |
| 103 | + |
| 104 | +# ------------------------- Clean up build environment ------------------------- |
| 105 | +- name: Clean build directory |
| 106 | + file: |
| 107 | + state: absent |
| 108 | + path: "{{ v2v_build_dir }}/" |
| 109 | + |
| 110 | +- name: Ensure build dependenciess are removed |
| 111 | + yum: |
| 112 | + name: "{{ item.name }}" |
| 113 | + state: absent |
| 114 | + with_items: "{{ pkgs_after_builddeps.results | difference(pkgs_before_builddeps.results) }}" |
0 commit comments