ansible: copy resulting openwrt image to correct location
authorChristian Pointner <equinox@realraum.at>
Fri, 4 May 2018 20:56:50 +0000 (22:56 +0200)
committerChristian Pointner <equinox@realraum.at>
Fri, 4 May 2018 20:56:50 +0000 (22:56 +0200)
ansible/.gitignore
ansible/roles/openwrt-image/defaults/main.yml
ansible/roles/openwrt-image/tasks/00-fetch.yml [deleted file]
ansible/roles/openwrt-image/tasks/02-prepare.yml [deleted file]
ansible/roles/openwrt-image/tasks/fetch.yml [new file with mode: 0644]
ansible/roles/openwrt-image/tasks/main.yml
ansible/roles/openwrt-image/tasks/prepare.yml [new file with mode: 0644]
ansible/tuer.yml

index 808abb8..d5e5f4b 100644 (file)
@@ -4,3 +4,4 @@
 *.retry
 .*.sw?
 /.cache/
+/files/
index e0724a8..92932fc 100644 (file)
@@ -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 (file)
index a69e65b..0000000
+++ /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 (file)
index 28bf10e..0000000
+++ /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 (file)
index 0000000..4b5b1c8
--- /dev/null
@@ -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
index d182a5b..5f9cc52 100644 (file)
@@ -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:
         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 (file)
index 0000000..30cd32b
--- /dev/null
@@ -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     }}"
index c73b047..f7c7bf4 100644 (file)
@@ -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
                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
 
             /etc/dropbear/authorized_keys: |-
               {% for key in noc_ssh_keys %}
-              key
+              {{ key }}
               {% endfor %}