From: nicoo Date: Thu, 19 Apr 2018 13:56:43 +0000 (+0200) Subject: Initial role for building OpenWRT images X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=785542e8910eae20c61fe025f6004f483c8bd777;p=noc.git Initial role for building OpenWRT images --- diff --git a/ansible/.gitignore b/ansible/.gitignore index 808abb8..3c4fe7e 100644 --- a/ansible/.gitignore +++ b/ansible/.gitignore @@ -1,5 +1,7 @@ /log /gpg/vault-keyring.gpg~ +/files/openwrt +/files/.cache *.pyc *.retry .*.sw? diff --git a/ansible/roles/openwrt-image/README.md b/ansible/roles/openwrt-image/README.md new file mode 100644 index 0000000..d56affe --- /dev/null +++ b/ansible/roles/openwrt-image/README.md @@ -0,0 +1,3 @@ +# Build OpenWRT images with Ansible + +## Configuration diff --git a/ansible/roles/openwrt-image/defaults/main.yml b/ansible/roles/openwrt-image/defaults/main.yml new file mode 100644 index 0000000..6c94890 --- /dev/null +++ b/ansible/roles/openwrt-image/defaults/main.yml @@ -0,0 +1,11 @@ +openwrt_release: 17.01.4 +download_dir: .cache/openwrt +openwrt_tarball_basename: lede-imagebuilder-{{ openwrt_release }}-{{ openwrt_arch }}{% if openwrt_target != 'generic' %}-{{ openwrt_target }}{% endif %}.Linux-x86_64 +openwrt_tarball_name: "{{ openwrt_tarball_basename }}.tar.xz" +openwrt_target: generic +openwrt_output_dir: files/openwrt + + +openwrt_packages_remove: [] +openwrt_packages_add: [] +openwrt_packages_extra: [] diff --git a/ansible/roles/openwrt-image/tasks/00-fetch.yml b/ansible/roles/openwrt-image/tasks/00-fetch.yml new file mode 100644 index 0000000..b3da57f --- /dev/null +++ b/ansible/roles/openwrt-image/tasks/00-fetch.yml @@ -0,0 +1,52 @@ +- name: Create download directory + file: + dest: "{{ download_dir }}" + state: directory + +- block: + - name: Generate OpenWrt download URLs + set_fact: + openwrt_url: + https://downloads.openwrt.org/releases/{{ openwrt_release }}/targets/{{ openwrt_arch | mandatory }}/{{ openwrt_target }} + + - name: Download sha256sums + get_url: + url: "{{ openwrt_url }}/sha256sums" + dest: "{{ download_dir }}/{{ openwrt_tarball_basename }}.sha256" + + - name: Download sha256sums.asc + get_url: + url: "{{ openwrt_url }}/sha256sums.asc" + dest: "{{ download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc" + + - name: Check OpenPGP signature + command: gpg --verify "{{ download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc" + changed_when: False + + - name: Extract SHA256 hash of the imagebuilder archive + command: grep '{{ openwrt_tarball_name }}' "{{ download_dir }}/{{ openwrt_tarball_basename }}.sha256" + register: sha256 + changed_when: False + + - name: Download imagebuilder + get_url: + url: "{{ openwrt_url }}/{{ openwrt_tarball_name }}" #lede-imagebuilder-{{ openwrt_release }}-{{ openwrt_arch }}.Linux-x86_64.tar.xz" + dest: "{{ download_dir }}/{{ openwrt_tarball_name }}" + checksum: sha256:{{ sha256.stdout.split(' ') | first }} + + # /!\ This needs to be the last task in 00-fetch.yml +# - set_fact: +# openwrt_imgbuilder_tarball: > +# {{ download_dir }}/{{ openwrt_tarball_name }} + + rescue: + - name: Delete downloaded artifacts + file: + path: "{{ item }}" + state: absent + with_items: + - "{{ download_dir }}/{{ openwrt_tarball_basename }}.sha256" + - "{{ download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc" + - "{{ download_dir }}/{{ openwrt_tarball_name }}" + - fail: + msg: Something borked diff --git a/ansible/roles/openwrt-image/tasks/02-prepare.yml b/ansible/roles/openwrt-image/tasks/02-prepare.yml new file mode 100644 index 0000000..277cc02 --- /dev/null +++ b/ansible/roles/openwrt-image/tasks/02-prepare.yml @@ -0,0 +1 @@ +- diff --git a/ansible/roles/openwrt-image/tasks/main.yml b/ansible/roles/openwrt-image/tasks/main.yml new file mode 100644 index 0000000..a7641c2 --- /dev/null +++ b/ansible/roles/openwrt-image/tasks/main.yml @@ -0,0 +1,58 @@ +- include: 00-fetch.yml + when: openwrt_imgbuilder_tarball is not defined + +- name: Create temporary build directory + command: mktemp -d openwrt-{{ ansible_hostname }}.XXXXXX + register: tmpdir + +- set_fact: + openwrt_imgbuilder_dir: "{{ tmpdir.stdout }}" + openwrt_imgbuilder_files: "{{ tmpdir.stdout }}/files" + +- name: Create the directory for slipstreamed files + file: + path: "{{ openwrt_imgbuilder_files }}" + state: directory + + +- block: +# - unarchive: +# copy: False +# src: "{{ download_dir }}/{{ openwrt_tarball_name }}" +# dest: "{{ openwrt_imgbuilder_dir }}" + + - name: Decompress the OpenWrt image builder + command: >- + tar -xf "{{ download_dir }}/{{ openwrt_tarball_name }}" + -C "{{ openwrt_imgbuilder_dir }}" + +# - include: 02-prepare.yml + + - name: Create the output directory for built images + file: + path: "{{ openwrt_output_dir }}" + state: directory + + - name: Build the OpenWrt image + shell: >- + make -C {{ openwrt_imgbuilder_dir }}/{{ openwrt_tarball_basename }} image + + FILES="{{ openwrt_imgbuilder_files }}" + + PACKAGES=" + {% for x in openwrt_packages_remove %}-{{x}} {% endfor %} + {% for x in openwrt_packages_add %} {{x}} {% endfor %} + {% for x in openwrt_packages_extra %} {{x}} {% endfor %} + " + BIN_DIR="{{ openwrt_output_dir }}" + + {% if openwrt_extra_name is defined %} + EXTRA_IMAGE_NAME="{{ openwrt_extra_name }}" + {% endif %} + + + always: + - name: Delete the temporary build directory + file: + path: "{{ openwrt_imgbuilder_dir }}" + state: absent