From 725c9fb96a3faf5bde0d742fe6c99ed4a864a008 Mon Sep 17 00:00:00 2001 From: Jochen Demmer Date: Sun, 21 Aug 2022 10:05:53 +0200 Subject: [PATCH 1/6] updated readme --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 535be90..e2ea151 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,21 @@ OpenWrt typically is being used in small environments but this collection is a g Click the link for the [documentation.](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection) Here is a [Youtube video](https://youtu.be/f1qrP3AagLM) I made in order to introduce it. Currently the documentation is German only but when the basics in Ansible are done and the documentation approaches a finshed state, I will translate it into English. + +Sections: +- [Ansible OpenWrt general usage](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection) +- [Ansible OpenWrt Batman-adv](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleBatmanadv) +- [Ansible OpenWrt DHCP](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleDHCP) +- [Ansible OpenWrt Dropbear SSH](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleDropbear) +- [Ansible OpenWrt Firewall](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleFirewall) +- [Ansible OpenWrt Network](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleNetwork) +- [Ansible OpenWrt Packages](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RollePackages) +- [Ansible OpenWrt Restic Backup](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleRestic) +- [Ansible OpenWrt SQM QoS](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleSqm) +- [Ansible OpenWrt Service](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleServices) +- [Ansible OpenWrt Syste](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleSystem) +- [Ansible OpenWrt Wireguard](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleWireguard) +- [Ansible OpenWrt Wireless](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleWireless) +- [Ansible OpenWrt bmx7](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleBmx7) +- [Ansible OpenWrt babeld](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleBabeld) +- [Ansible OpenWrt Imagebuilder](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection/RolleImagebuilder) From 2e46757ac1581108a756ca9f044edb7fbfc47966 Mon Sep 17 00:00:00 2001 From: Jochen Demmer Date: Sun, 21 Aug 2022 12:08:20 +0200 Subject: [PATCH 2/6] updated imagebuilder functions this role is actually not able to handle imagebuilder envs only some routines to prepare for it have been added --- .../ansible_openwrtservices/defaults/main.yml | 4 +++- roles/ansible_openwrtservices/tasks/main.yml | 22 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/roles/ansible_openwrtservices/defaults/main.yml b/roles/ansible_openwrtservices/defaults/main.yml index c74e0b7..2a9353a 100644 --- a/roles/ansible_openwrtservices/defaults/main.yml +++ b/roles/ansible_openwrtservices/defaults/main.yml @@ -1,3 +1,5 @@ --- # defaults file for ansible_openwrtservices -openwrt_services_deploypath: "/etc/rc.local" +openwrt_services_deployroot: "/" +openwrt_services_deploypath: "{{ openwrt_services_deployroot }}etc" +openwrt_services_deployfile: "rc.local" diff --git a/roles/ansible_openwrtservices/tasks/main.yml b/roles/ansible_openwrtservices/tasks/main.yml index 757cea6..0c0f37a 100644 --- a/roles/ansible_openwrtservices/tasks/main.yml +++ b/roles/ansible_openwrtservices/tasks/main.yml @@ -1,25 +1,37 @@ --- # tasks file for ansible_openwrtservices +# todo +# missing routine for enable as well as for disabling services in imagebuilder... +# it's only adding or removing a link, but I need the exact link name it would have been used +# in a real openwrt device, otherwise there could be conflicts - name: Enable Serices command: /etc/init.d/{{ item }} enable loop: "{{ openwrt_services_enabled }}" - when: openwrt_services_enabled is defined + when: + - openwrt_services_enabled is defined + - not openwrt_services_runimagebuilder | default(false) - name: Start Services command: /etc/init.d/{{ item }} start loop: "{{ openwrt_services_enabled }}" - when: openwrt_services_enabled is defined + when: + - openwrt_services_enabled is defined + - not openwrt_services_runimagebuilder | default(false) - name: Disable Services command: /etc/init.d/{{ item }} disable loop: "{{ openwrt_services_disabled }}" - when: openwrt_services_disabled is defined + when: + - openwrt_services_disabled is defined + - not openwrt_services_runimagebuilder | default(false) - name: Stop Services command: /etc/init.d/{{ item }} stop loop: "{{ openwrt_services_disabled }}" - when: openwrt_services_disabled is defined + when: + - openwrt_services_disabled is defined + - not openwrt_services_runimagebuilder | default(false) - name: Setup Start Scripts in /etc/rc.local template: src: rc.local.jinja2 - dest: "{{ openwrt_services_deploypath }}" + dest: "{{ openwrt_services_deploypath }}/{{ openwrt_services_deployfile }}" owner: root group: root mode: 0600 From 16ad57bf2255ca2b39d1f4ff80f1845fb400b764 Mon Sep 17 00:00:00 2001 From: Jochen Demmer Date: Sun, 21 Aug 2022 12:39:50 +0200 Subject: [PATCH 3/6] removed owner and group directives for imagebuilder they are not really needed since ansible connects as root to real devices anyhow --- roles/ansible_openwrtbabeld/tasks/main.yml | 2 -- roles/ansible_openwrtbmx7/tasks/main.yml | 4 ---- roles/ansible_openwrtdhcp/tasks/main.yml | 2 -- roles/ansible_openwrtnetwork/tasks/main.yml | 2 -- roles/ansible_openwrtservices/tasks/main.yml | 2 -- roles/ansible_openwrtsystem/tasks/kernel.yml | 4 ---- roles/ansible_openwrtsystem/tasks/main.yml | 2 -- roles/ansible_openwrtwireless/tasks/main.yml | 2 -- 8 files changed, 20 deletions(-) diff --git a/roles/ansible_openwrtbabeld/tasks/main.yml b/roles/ansible_openwrtbabeld/tasks/main.yml index 712481a..8f15572 100644 --- a/roles/ansible_openwrtbabeld/tasks/main.yml +++ b/roles/ansible_openwrtbabeld/tasks/main.yml @@ -14,8 +14,6 @@ ansible.builtin.template: src: getprefix.sh.jinja2 dest: /root/getprefix.sh - owner: root - group: root mode: 0744 when: not openwrt_babeld_runimagebuilder | default(false) diff --git a/roles/ansible_openwrtbmx7/tasks/main.yml b/roles/ansible_openwrtbmx7/tasks/main.yml index bc2daa4..8fd2f9b 100644 --- a/roles/ansible_openwrtbmx7/tasks/main.yml +++ b/roles/ansible_openwrtbmx7/tasks/main.yml @@ -30,8 +30,6 @@ template: src: getprefix.sh.jinja2 dest: /root/getprefix.sh - owner: root - group: root mode: 0744 - name: register dynamic prefixes shell: /root/getprefix.sh @@ -43,8 +41,6 @@ template: src: bmx7.jinja2 dest: /etc/config/bmx7 - owner: root - group: root mode: 0600 notify: restart bmx7 - name: enable bmx7 service diff --git a/roles/ansible_openwrtdhcp/tasks/main.yml b/roles/ansible_openwrtdhcp/tasks/main.yml index 4b7e044..5cf2c45 100644 --- a/roles/ansible_openwrtdhcp/tasks/main.yml +++ b/roles/ansible_openwrtdhcp/tasks/main.yml @@ -7,8 +7,6 @@ template: src: dhcp.jinja2 dest: "{{ openwrt_dhcp_deployroot }}{{ openwrt_dhcp_deploypath }}/{{ openwrt_dhcp_deployfile }}" - owner: root - group: root mode: 0600 notify: restart dnsmasq diff --git a/roles/ansible_openwrtnetwork/tasks/main.yml b/roles/ansible_openwrtnetwork/tasks/main.yml index 904aec5..d1247b1 100644 --- a/roles/ansible_openwrtnetwork/tasks/main.yml +++ b/roles/ansible_openwrtnetwork/tasks/main.yml @@ -27,7 +27,5 @@ ansible.builtin.template: src: network.jinja2 dest: "{{ openwrt_network_deploypath }}/{{ openwrt_network_deployfile }}" - owner: root - group: root mode: 0600 notify: restart network diff --git a/roles/ansible_openwrtservices/tasks/main.yml b/roles/ansible_openwrtservices/tasks/main.yml index 0c0f37a..9c70833 100644 --- a/roles/ansible_openwrtservices/tasks/main.yml +++ b/roles/ansible_openwrtservices/tasks/main.yml @@ -32,7 +32,5 @@ template: src: rc.local.jinja2 dest: "{{ openwrt_services_deploypath }}/{{ openwrt_services_deployfile }}" - owner: root - group: root mode: 0600 when: openwrt_scriptlinesafterboot is defined diff --git a/roles/ansible_openwrtsystem/tasks/kernel.yml b/roles/ansible_openwrtsystem/tasks/kernel.yml index b318de3..94fd262 100644 --- a/roles/ansible_openwrtsystem/tasks/kernel.yml +++ b/roles/ansible_openwrtsystem/tasks/kernel.yml @@ -13,8 +13,6 @@ src: "kernellogging.conf.jinja2" dest: "{{ openwrt_system_deploypath_kernellogging }}/{{ openwrt_system_deployfile_kernellogging }}" mode: 0644 - owner: "root" - group: "root" when: not openwrt_system_kernellogonconsole - name: Make sure kernel sysctl deploypath exists ansible.builtin.file: @@ -25,5 +23,3 @@ src: sysctl.conf.jinja2 dest: "{{ openwrt_system_deploypath_sysctl }}/{{ openwrt_system_deployfile_sysctl }}" mode: 0644 - owner: "root" - group: "root" diff --git a/roles/ansible_openwrtsystem/tasks/main.yml b/roles/ansible_openwrtsystem/tasks/main.yml index 0f6d0a1..eea351c 100644 --- a/roles/ansible_openwrtsystem/tasks/main.yml +++ b/roles/ansible_openwrtsystem/tasks/main.yml @@ -12,6 +12,4 @@ ansible.builtin.template: src: system.jinja2 dest: "{{ openwrt_system_deploypath }}/{{ openwrt_system_deployfile }}" - owner: root - group: root mode: 0600 diff --git a/roles/ansible_openwrtwireless/tasks/main.yml b/roles/ansible_openwrtwireless/tasks/main.yml index 14150ab..a2eb1f2 100644 --- a/roles/ansible_openwrtwireless/tasks/main.yml +++ b/roles/ansible_openwrtwireless/tasks/main.yml @@ -4,8 +4,6 @@ template: src: "wireless.jinja2" dest: "{{ openwrt_wireless_deploypath }}" - owner: "root" - group: "root" mode: "0600" when: openwrt_wifi_devices is defined notify: restart wireless From 12f4361be24a78c09ffbedbef0b126fadda3d700 Mon Sep 17 00:00:00 2001 From: Jochen Demmer Date: Sun, 21 Aug 2022 13:01:15 +0200 Subject: [PATCH 4/6] optimizations for imagebuilder make sure deployroot vars and such in defaults also make sure that deploypath exists in every single role --- roles/ansible_openwrtacme/tasks/main.yml | 4 ++++ roles/ansible_openwrtbatmanadv/defaults/main.yml | 5 ++++- roles/ansible_openwrtbatmanadv/tasks/main.yml | 4 ++++ roles/ansible_openwrtbmx7/defaults/main.yml | 5 ++++- roles/ansible_openwrtbmx7/tasks/main.yml | 4 ++++ roles/ansible_openwrtdhcp/tasks/main.yml | 4 ++++ roles/ansible_openwrtfirewall/tasks/main.yml | 4 ++++ roles/ansible_openwrtrestic/tasks/main.yml | 4 ++++ roles/ansible_openwrtservices/tasks/main.yml | 4 ++++ 9 files changed, 36 insertions(+), 2 deletions(-) diff --git a/roles/ansible_openwrtacme/tasks/main.yml b/roles/ansible_openwrtacme/tasks/main.yml index d688963..95b2adb 100644 --- a/roles/ansible_openwrtacme/tasks/main.yml +++ b/roles/ansible_openwrtacme/tasks/main.yml @@ -1,5 +1,9 @@ --- # tasks file for ansible_openwrtacme +- name: make sure deploypath is present + ansible.builtin.file: + path: "{{ openwrt_acme_deploypath }}" + state: directory - name: Install packages opkg: name: "acme,acme-dnsapi,luci-app-acme" diff --git a/roles/ansible_openwrtbatmanadv/defaults/main.yml b/roles/ansible_openwrtbatmanadv/defaults/main.yml index 16aebe2..7e50640 100644 --- a/roles/ansible_openwrtbatmanadv/defaults/main.yml +++ b/roles/ansible_openwrtbatmanadv/defaults/main.yml @@ -1,2 +1,5 @@ --- -# defaults file for ansible_openwrtbatmanadv \ No newline at end of file +# defaults file for ansible_openwrtbatmanadv +openwrt_batmanadv_deployroot: "/" +openwrt_batmanadv_deploypath: "{{ openwrt_batmanadv_deployroot }}etc/config" +openwrt_batmanadv_deployfile: "batman-adv" diff --git a/roles/ansible_openwrtbatmanadv/tasks/main.yml b/roles/ansible_openwrtbatmanadv/tasks/main.yml index f56a3f7..8553394 100644 --- a/roles/ansible_openwrtbatmanadv/tasks/main.yml +++ b/roles/ansible_openwrtbatmanadv/tasks/main.yml @@ -1,5 +1,9 @@ --- # tasks file for ansible_openwrtbatmanadv +- name: make sure deploypath is present + ansible.builtin.file: + path: "{{ openwrt_batmanadv_deploypath }}" + state: directory - name: Install batman-adv software package: name: diff --git a/roles/ansible_openwrtbmx7/defaults/main.yml b/roles/ansible_openwrtbmx7/defaults/main.yml index 4c691f8..875827f 100644 --- a/roles/ansible_openwrtbmx7/defaults/main.yml +++ b/roles/ansible_openwrtbmx7/defaults/main.yml @@ -1,2 +1,5 @@ --- -# defaults file for ansible_openwrtbmx7 \ No newline at end of file +# defaults file for ansible_openwrtbmx7 +openwrt_bmx7_deployroot: "/" +openwrt_bmx7_deploypath: "{{ openwrt_bmx7_deployroot }}etc/config" +openwrt_bmx7_deployfile: "bmx7" diff --git a/roles/ansible_openwrtbmx7/tasks/main.yml b/roles/ansible_openwrtbmx7/tasks/main.yml index 8fd2f9b..77f0ce3 100644 --- a/roles/ansible_openwrtbmx7/tasks/main.yml +++ b/roles/ansible_openwrtbmx7/tasks/main.yml @@ -1,5 +1,9 @@ --- # tasks file for ansible_openwrtbmx7 +- name: make sure deploypath is present + ansible.builtin.file: + path: "{{ openwrt_bmx7_deploypath }}" + state: directory - name: Refresh opkg so packages will be found shell: opkg update - name: Install json plugin diff --git a/roles/ansible_openwrtdhcp/tasks/main.yml b/roles/ansible_openwrtdhcp/tasks/main.yml index 5cf2c45..c7a7495 100644 --- a/roles/ansible_openwrtdhcp/tasks/main.yml +++ b/roles/ansible_openwrtdhcp/tasks/main.yml @@ -1,5 +1,9 @@ --- # tasks file for ansible_openwrtdhcp +- name: make sure deploypath is present + ansible.builtin.file: + path: "{{ openwrt_dhcp_deploypath }}" + state: directory - name: merge dhcp group pools include_tasks: merge.yml when: openwrt_dhcp_poolsgroup is defined diff --git a/roles/ansible_openwrtfirewall/tasks/main.yml b/roles/ansible_openwrtfirewall/tasks/main.yml index c557817..9c43e3f 100644 --- a/roles/ansible_openwrtfirewall/tasks/main.yml +++ b/roles/ansible_openwrtfirewall/tasks/main.yml @@ -1,5 +1,9 @@ --- # tasks file for ansible_openwrtfirewall +- name: make sure deploypath config exists + ansible.builtin.file: + path: "{{ openwrt_firewall_deploypath }}" + state: directory - name: declare emtpy zone array set_fact: openwrt_firewall_zonesactive: [] diff --git a/roles/ansible_openwrtrestic/tasks/main.yml b/roles/ansible_openwrtrestic/tasks/main.yml index 5604440..96bb49a 100644 --- a/roles/ansible_openwrtrestic/tasks/main.yml +++ b/roles/ansible_openwrtrestic/tasks/main.yml @@ -1,5 +1,9 @@ --- # tasks file for ansible_openwrtrestic +- name: make sure deploypath config exists + ansible.builtin.file: + path: "{{ openwrt_restic_deploypath }}" + state: directory - name: Installation and preparation include_tasks: 1install.yml - name: SSH setup diff --git a/roles/ansible_openwrtservices/tasks/main.yml b/roles/ansible_openwrtservices/tasks/main.yml index 9c70833..f680da0 100644 --- a/roles/ansible_openwrtservices/tasks/main.yml +++ b/roles/ansible_openwrtservices/tasks/main.yml @@ -4,6 +4,10 @@ # missing routine for enable as well as for disabling services in imagebuilder... # it's only adding or removing a link, but I need the exact link name it would have been used # in a real openwrt device, otherwise there could be conflicts +- name: make sure deploypath config exists + ansible.builtin.file: + path: "{{ openwrt_services_deploypath }}" + state: directory - name: Enable Serices command: /etc/init.d/{{ item }} enable loop: "{{ openwrt_services_enabled }}" From de18881ffc56d79b1c7bfb9bd28ef685359094aa Mon Sep 17 00:00:00 2001 From: Jochen Demmer Date: Sun, 21 Aug 2022 13:39:14 +0200 Subject: [PATCH 5/6] optimizations imagebuilder conditionals set errors removed --- roles/ansible_openwrtbatmanadv/tasks/main.yml | 4 ++- roles/ansible_openwrtbmx7/tasks/main.yml | 36 ++++++++++++++----- roles/ansible_openwrtdhcp/tasks/main.yml | 6 ++-- roles/ansible_openwrtfirewall/tasks/main.yml | 6 ++-- roles/ansible_openwrtrestic/defaults/main.yml | 5 +-- .../ansible_openwrtrestic/tasks/1install.yml | 5 +++ roles/ansible_openwrtrestic/tasks/main.yml | 7 ++-- 7 files changed, 49 insertions(+), 20 deletions(-) diff --git a/roles/ansible_openwrtbatmanadv/tasks/main.yml b/roles/ansible_openwrtbatmanadv/tasks/main.yml index 8553394..f013fc7 100644 --- a/roles/ansible_openwrtbatmanadv/tasks/main.yml +++ b/roles/ansible_openwrtbatmanadv/tasks/main.yml @@ -2,7 +2,7 @@ # tasks file for ansible_openwrtbatmanadv - name: make sure deploypath is present ansible.builtin.file: - path: "{{ openwrt_batmanadv_deploypath }}" + path: "{{ openwrt_batmanadv_deploypath }}" state: directory - name: Install batman-adv software package: @@ -11,4 +11,6 @@ - alfred - batctl-full state: present + when: + - not openwrt_batmanadv_runimagebuilder | default(false) diff --git a/roles/ansible_openwrtbmx7/tasks/main.yml b/roles/ansible_openwrtbmx7/tasks/main.yml index 77f0ce3..aca9413 100644 --- a/roles/ansible_openwrtbmx7/tasks/main.yml +++ b/roles/ansible_openwrtbmx7/tasks/main.yml @@ -1,50 +1,68 @@ --- # tasks file for ansible_openwrtbmx7 - name: make sure deploypath is present - ansible.builtin.file: - path: "{{ openwrt_bmx7_deploypath }}" - state: directory + ansible.builtin.file: + path: "{{ openwrt_bmx7_deploypath }}" + state: directory - name: Refresh opkg so packages will be found shell: opkg update + when: + - not openwrt_bmx7_runimagebuilder | default(false) - name: Install json plugin package: name: bmx7-json state: present - when: openwrt_bmx7_plugin_json_enabled is defined + when: + - openwrt_bmx7_plugin_json_enabled is defined + - not openwrt_bmx7_runimagebuilder | default(false) - name: Install topology plugin package: name: bmx7-topology state: present - when: openwrt_bmx7_plugin_topology_enabled is defined + when: + - openwrt_bmx7_plugin_topology_enabled is defined + - not openwrt_bmx7_runimagebuilder | default(false) - name: Install sms plugin package: name: bmx7-sms state: present - when: openwrt_bmx7_plugin_sms_enabled is defined + when: + - openwrt_bmx7_plugin_sms_enabled is defined + - not openwrt_bmx7_runimagebuilder | default(false) - name: Install tun plugin package: name: bmx7-tun state: present - when: openwrt_bmx7_plugin_tun_enabled is defined + when: + - openwrt_bmx7_plugin_tun_enabled is defined + - not openwrt_bmx7_runimagebuilder | default(false) - name: Install jq in order to be able to parse ifstatus package: name: jq state: present + when: + - not openwrt_bmx7_runimagebuilder | default(false) - name: Install getprefix script template: src: getprefix.sh.jinja2 dest: /root/getprefix.sh mode: 0744 + when: + - not openwrt_bmx7_runimagebuilder | default(false) - name: register dynamic prefixes shell: /root/getprefix.sh register: openwrt_bmx7_collectedprefixes + when: + - not openwrt_bmx7_runimagebuilder | default(false) - name: register local ula shell: /sbin/uci get network.globals.ula_prefix register: openwrt_bmx7_ulaprefix + when: + - not openwrt_bmx7_runimagebuilder | default(false) - name: Provide bmx7 configuration template: src: bmx7.jinja2 - dest: /etc/config/bmx7 + dest: "{{ openwrt_bmx7_deploypath }}/{{ openwrt_bmx7_deployfile }}" mode: 0600 notify: restart bmx7 - name: enable bmx7 service @@ -52,4 +70,6 @@ name: bmx7 state: started enabled: yes + when: + - not openwrt_bmx7_runimagebuilder | default(false) diff --git a/roles/ansible_openwrtdhcp/tasks/main.yml b/roles/ansible_openwrtdhcp/tasks/main.yml index c7a7495..e49c7a3 100644 --- a/roles/ansible_openwrtdhcp/tasks/main.yml +++ b/roles/ansible_openwrtdhcp/tasks/main.yml @@ -1,9 +1,9 @@ --- # tasks file for ansible_openwrtdhcp - name: make sure deploypath is present - ansible.builtin.file: - path: "{{ openwrt_dhcp_deploypath }}" - state: directory + ansible.builtin.file: + path: "{{ openwrt_dhcp_deploypath }}" + state: directory - name: merge dhcp group pools include_tasks: merge.yml when: openwrt_dhcp_poolsgroup is defined diff --git a/roles/ansible_openwrtfirewall/tasks/main.yml b/roles/ansible_openwrtfirewall/tasks/main.yml index 9c43e3f..265cffc 100644 --- a/roles/ansible_openwrtfirewall/tasks/main.yml +++ b/roles/ansible_openwrtfirewall/tasks/main.yml @@ -1,9 +1,9 @@ --- # tasks file for ansible_openwrtfirewall - name: make sure deploypath config exists - ansible.builtin.file: - path: "{{ openwrt_firewall_deploypath }}" - state: directory + ansible.builtin.file: + path: "{{ openwrt_firewall_deploypath }}" + state: directory - name: declare emtpy zone array set_fact: openwrt_firewall_zonesactive: [] diff --git a/roles/ansible_openwrtrestic/defaults/main.yml b/roles/ansible_openwrtrestic/defaults/main.yml index 89f95df..70fbc14 100644 --- a/roles/ansible_openwrtrestic/defaults/main.yml +++ b/roles/ansible_openwrtrestic/defaults/main.yml @@ -13,9 +13,10 @@ openwrt_restic_keepweekly: 3 openwrt_restic_keepdaily: 9 openwrt_restic_keepmonthly: 2 openwrt_restic_deployroot: "/" -openwrt_restic_deploypath: "{{ openwrt_restic_deployroot }}etc/restic" +openwrt_restic_deploypath: "{{ openwrt_restic_deployroot }}etc" +openwrt_restic_deployfile: "restic" openwrt_restic_deploypath_sysupgrade: "{{ openwrt_restic_deployroot }}etc" -openwrt_restic_deployfilie_sysupgrade: "sysupgrade.conf" +openwrt_restic_deployfile_sysupgrade: "sysupgrade.conf" openwrt_restic_deploypath_passwordfile: "{{ openwrt_restic_deployroot }}etc" openwrt_restic_deployfile_passwordfile: "resticpassword" openwrt_restic_deploypath_knownhosts: "{{ openwrt_restic_deployroot }}root/.ssh" diff --git a/roles/ansible_openwrtrestic/tasks/1install.yml b/roles/ansible_openwrtrestic/tasks/1install.yml index cc94097..4b592b5 100644 --- a/roles/ansible_openwrtrestic/tasks/1install.yml +++ b/roles/ansible_openwrtrestic/tasks/1install.yml @@ -5,6 +5,11 @@ state: present update_cache: true when: not openwrt_restic_runimagebuilder | default(false) +- name: make sure sysupgrade.conf file exists + ansible.builtin.file: + path: "{{ openwrt_restic_deploypath_sysupgrade }}/{{ openwrt_restic_deployfile_sysupgrade }}" + mode: '0644' + state: touch - name: add /etc/config/installed.packages to sysupgrade config lineinfile: path: "{{ openwrt_restic_deploypath_sysupgrade }}/{{ openwrt_restic_deployfile_sysupgrade }}" diff --git a/roles/ansible_openwrtrestic/tasks/main.yml b/roles/ansible_openwrtrestic/tasks/main.yml index 96bb49a..724b66c 100644 --- a/roles/ansible_openwrtrestic/tasks/main.yml +++ b/roles/ansible_openwrtrestic/tasks/main.yml @@ -1,9 +1,9 @@ --- # tasks file for ansible_openwrtrestic - name: make sure deploypath config exists - ansible.builtin.file: - path: "{{ openwrt_restic_deploypath }}" - state: directory + ansible.builtin.file: + path: "{{ openwrt_restic_deploypath }}" + state: directory - name: Installation and preparation include_tasks: 1install.yml - name: SSH setup @@ -19,6 +19,7 @@ - not 'config file already exists' in restic_init.stderr - not 'config already initialized' in restic_init.stderr - not 'config already exists' in restic_init.stderr + - not openwrt_restic_runimagebuilder | default(false) - name: "setup cron jobs" include_tasks: 5cron.yml when: not openwrt_restic_runimagebuilder | default(false) From deb26bf086d9705d661a09d6026ca0e4ac55115a Mon Sep 17 00:00:00 2001 From: Jochen Demmer Date: Sun, 21 Aug 2022 13:39:46 +0200 Subject: [PATCH 6/6] new role ansible_openwrtimagebuilder, not finished some more work to be done --- roles/ansible_openwrtimagebuilder/README.md | 1 + .../defaults/main.yml | 2 + .../handlers/main.yml | 2 + .../ansible_openwrtimagebuilder/meta/main.yml | 52 +++++++++++++++++ .../tasks/main.yml | 57 +++++++++++++++++++ .../tests/inventory | 2 + .../tests/test.yml | 5 ++ .../ansible_openwrtimagebuilder/vars/main.yml | 6 ++ 8 files changed, 127 insertions(+) create mode 100644 roles/ansible_openwrtimagebuilder/README.md create mode 100644 roles/ansible_openwrtimagebuilder/defaults/main.yml create mode 100644 roles/ansible_openwrtimagebuilder/handlers/main.yml create mode 100644 roles/ansible_openwrtimagebuilder/meta/main.yml create mode 100644 roles/ansible_openwrtimagebuilder/tasks/main.yml create mode 100644 roles/ansible_openwrtimagebuilder/tests/inventory create mode 100644 roles/ansible_openwrtimagebuilder/tests/test.yml create mode 100644 roles/ansible_openwrtimagebuilder/vars/main.yml diff --git a/roles/ansible_openwrtimagebuilder/README.md b/roles/ansible_openwrtimagebuilder/README.md new file mode 100644 index 0000000..a77a7a6 --- /dev/null +++ b/roles/ansible_openwrtimagebuilder/README.md @@ -0,0 +1 @@ +https://github.com/imp1sh/ansible_openwrt diff --git a/roles/ansible_openwrtimagebuilder/defaults/main.yml b/roles/ansible_openwrtimagebuilder/defaults/main.yml new file mode 100644 index 0000000..ee9642c --- /dev/null +++ b/roles/ansible_openwrtimagebuilder/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for ansible_openwrtimagebuilder diff --git a/roles/ansible_openwrtimagebuilder/handlers/main.yml b/roles/ansible_openwrtimagebuilder/handlers/main.yml new file mode 100644 index 0000000..b877f8c --- /dev/null +++ b/roles/ansible_openwrtimagebuilder/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for ansible_openwrtimagebuilder diff --git a/roles/ansible_openwrtimagebuilder/meta/main.yml b/roles/ansible_openwrtimagebuilder/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/ansible_openwrtimagebuilder/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/ansible_openwrtimagebuilder/tasks/main.yml b/roles/ansible_openwrtimagebuilder/tasks/main.yml new file mode 100644 index 0000000..9868447 --- /dev/null +++ b/roles/ansible_openwrtimagebuilder/tasks/main.yml @@ -0,0 +1,57 @@ +--- +# tasks file for ansible_openwrtimagebuilder +- name: make sure builddir exists + ansible.builtin.file: + path: "{{ openwrt_imagebuilder_builddir }}" + state: directory +- name: make sure outputdir exists + ansible.builtin.file: + path: "{{ openwrt_imagebuilder_outputdir }}" + state: directory +- name: download and extract imagebuilder + ansible.builtin.unarchive: + src: "{{ openwrt_imagebuilder_downloadurl }}" + list_files: yes + remote_src: yes + dest: "{{ openwrt_imagebuilder_builddir }}" + register: openwrt_imagebuilder_extraction +- name: get extracted folder name + set_fact: + openwrt_imagebuilder_extractedfolder: "{{ openwrt_imagebuilder_extraction.files[0] }}" +- name: remove old files dir if exist + ansible.builtin.file: + path: "{{ openwrt_imagebuilder_builddir }}/{{ openwrt_imagebuilder_extractedfolder }}{{ openwrt_imagebuilder_filesdir }}" + state: absent +- name: create empty files dir + ansible.builtin.file: + path: "{{ openwrt_imagebuilder_builddir }}/{{ openwrt_imagebuilder_extractedfolder }}{{ openwrt_imagebuilder_filesdir }}" + state: directory +- name: set this files directory to use as openwrt deployroot for all compatible roles + set_fact: + "{{ item }}": "{{ openwrt_imagebuilder_builddir }}/{{ openwrt_imagebuilder_extractedfolder }}{{ openwrt_imagebuilder_filesdir }}/" + loop: + - openwrt_acme_deployroot + - openwrt_batmanadv_deployroot + - openwrt_babeld_deployroot + - openwrt_bmx7_deployroot + - openwrt_dhcp_deployroot + - openwrt_dropbear_deployroot + - openwrt_firewall_deployroot + - openwrt_network_deployroot + - openwrt_restic_deployroot + - openwrt_services_deployroot + - openwrt_system_deployroot +- name: run all openwrt roles that are compatible with imagebuilder + ansible.builtin.include_role: + name: "{{ item }}" + loop: + - imp1sh.ansible_openwrt.ansible_openwrtacme + - imp1sh.ansible_openwrt.ansible_openwrtbatmanadv + - imp1sh.ansible_openwrt.ansible_openwrtbabeld + - imp1sh.ansible_openwrt.ansible_openwrtdhcp + - imp1sh.ansible_openwrt.ansible_openwrtdropbear + - imp1sh.ansible_openwrt.ansible_openwrtfirewall + - imp1sh.ansible_openwrt.ansible_openwrtnetwork + - imp1sh.ansible_openwrt.ansible_openwrtrestic + - imp1sh.ansible_openwrt.ansible_openwrtsystem + #- imp1sh.ansible_openwrt.ansible_openwrtbmx7 diff --git a/roles/ansible_openwrtimagebuilder/tests/inventory b/roles/ansible_openwrtimagebuilder/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/ansible_openwrtimagebuilder/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/ansible_openwrtimagebuilder/tests/test.yml b/roles/ansible_openwrtimagebuilder/tests/test.yml new file mode 100644 index 0000000..5dd180a --- /dev/null +++ b/roles/ansible_openwrtimagebuilder/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - ansible_openwrtimagebuilder diff --git a/roles/ansible_openwrtimagebuilder/vars/main.yml b/roles/ansible_openwrtimagebuilder/vars/main.yml new file mode 100644 index 0000000..a6ea575 --- /dev/null +++ b/roles/ansible_openwrtimagebuilder/vars/main.yml @@ -0,0 +1,6 @@ +--- +# vars file for ansible_openwrtimagebuilder +openwrt_imagebuilder_builddir: "/tmp/openwrt_imagebuilder" +openwrt_imagebuilder_outputdir: "/tmp/openwrt_imagebuilder_images" +openwrt_imagebuilder_downloadurl: "https://downloads.openwrt.org/releases/22.03.0-rc6/targets/x86/64/openwrt-imagebuilder-22.03.0-rc6-x86-64.Linux-x86_64.tar.xz" +openwrt_imagebuilder_filesdir: "files"