From 3ca11d4bcb124eee97b958149c34201bdf83677c Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 4 May 2018 22:56:50 +0200 Subject: [PATCH] ansible: copy resulting openwrt image to correct location --- ansible/.gitignore | 1 + ansible/roles/openwrt-image/defaults/main.yml | 9 +++- ansible/roles/openwrt-image/tasks/00-fetch.yml | 53 ------------------ ansible/roles/openwrt-image/tasks/02-prepare.yml | 2 - ansible/roles/openwrt-image/tasks/fetch.yml | 48 +++++++++++++++++ ansible/roles/openwrt-image/tasks/main.yml | 63 +++++----------------- ansible/roles/openwrt-image/tasks/prepare.yml | 44 +++++++++++++++ ansible/tuer.yml | 19 ++++--- 8 files changed, 123 insertions(+), 116 deletions(-) delete mode 100644 ansible/roles/openwrt-image/tasks/00-fetch.yml delete mode 100644 ansible/roles/openwrt-image/tasks/02-prepare.yml create mode 100644 ansible/roles/openwrt-image/tasks/fetch.yml create mode 100644 ansible/roles/openwrt-image/tasks/prepare.yml diff --git a/ansible/.gitignore b/ansible/.gitignore index 808abb8..d5e5f4b 100644 --- a/ansible/.gitignore +++ b/ansible/.gitignore @@ -4,3 +4,4 @@ *.retry .*.sw? /.cache/ +/files/ diff --git a/ansible/roles/openwrt-image/defaults/main.yml b/ansible/roles/openwrt-image/defaults/main.yml index e0724a8..92932fc 100644 --- a/ansible/roles/openwrt-image/defaults/main.yml +++ b/ansible/roles/openwrt-image/defaults/main.yml @@ -1,11 +1,16 @@ --- +openwrt_variant: lede openwrt_release: 17.01.4 openwrt_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_basename: "{{ openwrt_variant }}-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_output_dir: files/openwrt/{{ inventory_hostname }} +openwrt_output_image_name_base: "{{ openwrt_variant }}-{{ openwrt_release }}-{{ openwrt_arch }}{% if openwrt_target != 'generic' %}-{{ openwrt_target }}{% endif %}" +openwrt_output_image_suffixes: + - squashfs-sysupgrade.bin + - squashfs-factory.bin openwrt_packages_remove: [] openwrt_packages_add: [] diff --git a/ansible/roles/openwrt-image/tasks/00-fetch.yml b/ansible/roles/openwrt-image/tasks/00-fetch.yml deleted file mode 100644 index a69e65b..0000000 --- a/ansible/roles/openwrt-image/tasks/00-fetch.yml +++ /dev/null @@ -1,53 +0,0 @@ ---- -- name: Create download directory - file: - dest: "{{ openwrt_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: "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256" - - - name: Download sha256sums.asc - get_url: - url: "{{ openwrt_url }}/sha256sums.asc" - dest: "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc" - - - name: Check OpenPGP signature - command: gpg --verify "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc" - changed_when: False - - - name: Extract SHA256 hash of the imagebuilder archive - command: grep '{{ openwrt_tarball_name }}' "{{ openwrt_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: "{{ openwrt_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: > -# {{ openwrt_download_dir }}/{{ openwrt_tarball_name }} - - rescue: - - name: Delete downloaded artifacts - file: - path: "{{ item }}" - state: absent - with_items: - - "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256" - - "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc" - - "{{ openwrt_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 deleted file mode 100644 index 28bf10e..0000000 --- a/ansible/roles/openwrt-image/tasks/02-prepare.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -- diff --git a/ansible/roles/openwrt-image/tasks/fetch.yml b/ansible/roles/openwrt-image/tasks/fetch.yml new file mode 100644 index 0000000..4b5b1c8 --- /dev/null +++ b/ansible/roles/openwrt-image/tasks/fetch.yml @@ -0,0 +1,48 @@ +--- +- name: Create download directory + file: + dest: "{{ openwrt_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: "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256" + + - name: Download sha256sums.asc + get_url: + url: "{{ openwrt_url }}/sha256sums.asc" + dest: "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc" + + - name: Check OpenPGP signature + command: gpg --verify "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc" + changed_when: False + + - name: Extract SHA256 hash of the imagebuilder archive + command: grep '{{ openwrt_tarball_name }}' "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256" + register: sha256 + changed_when: False + + - name: Download imagebuilder + get_url: + url: "{{ openwrt_url }}/{{ openwrt_tarball_name }}" + dest: "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}" + checksum: sha256:{{ sha256.stdout.split(' ') | first }} + + rescue: + - name: Delete downloaded artifacts + file: + path: "{{ item }}" + state: absent + with_items: + - "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256" + - "{{ openwrt_download_dir }}/{{ openwrt_tarball_basename }}.sha256.asc" + - "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}" + - fail: + msg: Something borked diff --git a/ansible/roles/openwrt-image/tasks/main.yml b/ansible/roles/openwrt-image/tasks/main.yml index d182a5b..5f9cc52 100644 --- a/ansible/roles/openwrt-image/tasks/main.yml +++ b/ansible/roles/openwrt-image/tasks/main.yml @@ -1,52 +1,9 @@ --- -- include: 00-fetch.yml +- include: fetch.yml when: openwrt_imgbuilder_tarball is not defined -- name: Create temporary build directory - command: mktemp --tmpdir -d openwrt-{{ ansible_hostname }}.XXXXXX - register: tmpdir - -- set_fact: - openwrt_imgbuilder_dir: "{{ tmpdir.stdout }}" - openwrt_imgbuilder_files: "{{ tmpdir.stdout }}/files" - -- name: Create the directories for mixins - file: - path: "{{ item }}" - state: directory - with_items: - - "{{ openwrt_imgbuilder_files }}" - - "{{ openwrt_mixin.files | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}" - - "{{ openwrt_mixin.content | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}" - -- name: Copy mixins in place [1/2] - copy: - src: "{{ item.value }}" - dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}" - with_dict: "{{ openwrt_mixin.files }}" - loop_control: - label: "{{ item.key }}" - -- name: Copy mixins in place [2/2] - copy: - content: "{{ item.value }}" - dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}" - with_dict: "{{ openwrt_mixin.content }}" - loop_control: - label: "{{ item.key }}" - - block: -# - unarchive: -# copy: False -# src: "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}" -# dest: "{{ openwrt_imgbuilder_dir }}" - - - name: Decompress the OpenWrt image builder - command: >- - tar -xf "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}" - -C "{{ openwrt_imgbuilder_dir }}" - -# - include: 02-prepare.yml + - include: prepare.yml - name: Create the output directory for built images file: @@ -64,12 +21,16 @@ make -C {{ openwrt_imgbuilder_dir }}/{{ openwrt_tarball_basename }} image FILES="{{ openwrt_imgbuilder_files }}" PACKAGES="{{ openwrt_packages }}" - BIN_DIR="{{ openwrt_output_dir }}" {% if openwrt_extra_name is defined %} EXTRA_IMAGE_NAME="{{ openwrt_extra_name }}" {% endif %} + - name: Copy newly built OpenWrt image + with_items: "{{ openwrt_output_image_suffixes }}" + copy: + src: "{{ openwrt_imgbuilder_dir }}/{{ openwrt_tarball_basename }}/bin/targets/{{ openwrt_arch }}/{{ openwrt_target }}/{{ openwrt_output_image_name_base }}-{{ item }}" + dest: "{{ openwrt_output_dir }}" -# always: -# - name: Delete the temporary build directory -# file: -# path: "{{ openwrt_imgbuilder_dir }}" -# state: absent + always: + - name: Delete the temporary build directory + file: + path: "{{ openwrt_imgbuilder_dir }}" + state: absent diff --git a/ansible/roles/openwrt-image/tasks/prepare.yml b/ansible/roles/openwrt-image/tasks/prepare.yml new file mode 100644 index 0000000..30cd32b --- /dev/null +++ b/ansible/roles/openwrt-image/tasks/prepare.yml @@ -0,0 +1,44 @@ +--- +- name: Create temporary build directory + command: mktemp --tmpdir -d openwrt-{{ inventory_hostname }}.XXXXXX + register: tmpdir + +- set_fact: + openwrt_imgbuilder_dir: "{{ tmpdir.stdout }}" + openwrt_imgbuilder_files: "{{ tmpdir.stdout }}/files" + +- name: Create the directories for mixins + file: + path: "{{ item }}" + state: directory + with_items: + - "{{ openwrt_imgbuilder_files }}" + - "{{ openwrt_mixin.files | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}" + - "{{ openwrt_mixin.content | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}" + +- name: Copy mixins in place [1/2] + copy: + src: "{{ item.value }}" + dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}" + with_dict: "{{ openwrt_mixin.files }}" + loop_control: + label: "{{ item.key }}" + +- name: Copy mixins in place [2/2] + copy: + content: "{{ item.value }}" + dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}" + with_dict: "{{ openwrt_mixin.content }}" + loop_control: + label: "{{ item.key }}" + +### TODO: this just hangs? +# - unarchive: +# copy: False +# src: "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}" +# dest: "{{ openwrt_imgbuilder_dir }}" + +- name: Decompress the OpenWrt image builder + command: >- + tar -xf "{{ openwrt_download_dir }}/{{ openwrt_tarball_name }}" + -C "{{ openwrt_imgbuilder_dir }}" diff --git a/ansible/tuer.yml b/ansible/tuer.yml index c73b047..f7c7bf4 100644 --- a/ansible/tuer.yml +++ b/ansible/tuer.yml @@ -43,6 +43,9 @@ vars: openwrt_arch: x86 openwrt_target: geode + openwrt_output_image_suffixes: + - combined-ext4.img.gz + - combined-squashfs.img openwrt_packages_remove: - ppp - ppp-mod-pppoe @@ -75,19 +78,19 @@ option proto 'static' option ipaddr '127.0.0.1' option netmask '255.0.0.0' - + config globals 'globals' option ula_prefix 'fdc9:e01f:83db::/48' - + config interface 'lan' option ifname 'eth0' option accept_ra '0' option proto 'static' - option ipaddr '192.168.33.7' - option netmask '255.255.255.0' - option gateway '192.168.33.1' - option dns '192.168.33.1' - option dns_search 'realraum.at' + option ipaddr '192.168.33.7' + option netmask '255.255.255.0' + option gateway '192.168.33.1' + option dns '192.168.33.1' + option dns_search 'realraum.at' /etc/config/dropbear: | config dropbear @@ -97,5 +100,5 @@ /etc/dropbear/authorized_keys: |- {% for key in noc_ssh_keys %} - key + {{ key }} {% endfor %} -- 1.7.10.4