From 4e8d375e3e6a28e93041e3d8117861881269896c Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 21 Nov 2023 11:37:34 -0500 Subject: [PATCH] draft converting to collection --- README.md | 12 +++--------- playbooks/bootstrap.yml | 14 ++++++++++++++ .../main.yml => playbooks/group_vars/openwrt.yml | 5 ++++- .../modules/command.sh | 0 library/openwrt_copy.sh => plugins/modules/copy.sh | 0 library/openwrt_file.sh => plugins/modules/file.sh | 0 .../modules/lineinfile.sh | 0 {library => plugins/modules}/nohup.py | 0 .../openwrt_nohup.sh => plugins/modules/nohup.sh | 0 library/openwrt_opkg.sh => plugins/modules/opkg.sh | 0 library/openwrt_ping.sh => plugins/modules/ping.sh | 0 .../modules/service.sh | 0 .../openwrt_setup.sh => plugins/modules/setup.sh | 0 .../openwrt_slurp.sh => plugins/modules/slurp.sh | 0 library/openwrt_stat.sh => plugins/modules/stat.sh | 0 .../openwrt_sysctl.sh => plugins/modules/sysctl.sh | 0 {library => plugins/modules}/uci.py | 0 library/openwrt_uci.sh => plugins/modules/uci.sh | 0 {vars_plugins => plugins/vars}/monkeypatch.py | 0 requirements.txt | 4 ---- {handlers => roles/pkg/handlers}/main.yml | 0 tasks/package.yml => roles/pkg/tasks/main.yml | 0 .../pkg/tasks/recommended.yml | 2 +- {files => roles/prep/files}/wrapper.sh | 0 {tasks => roles/prep/tasks}/main.yml | 4 +++- 25 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 playbooks/bootstrap.yml rename defaults/main.yml => playbooks/group_vars/openwrt.yml (91%) rename library/openwrt_command.sh => plugins/modules/command.sh (100%) rename library/openwrt_copy.sh => plugins/modules/copy.sh (100%) rename library/openwrt_file.sh => plugins/modules/file.sh (100%) rename library/openwrt_lineinfile.sh => plugins/modules/lineinfile.sh (100%) rename {library => plugins/modules}/nohup.py (100%) rename library/openwrt_nohup.sh => plugins/modules/nohup.sh (100%) rename library/openwrt_opkg.sh => plugins/modules/opkg.sh (100%) rename library/openwrt_ping.sh => plugins/modules/ping.sh (100%) rename library/openwrt_service.sh => plugins/modules/service.sh (100%) rename library/openwrt_setup.sh => plugins/modules/setup.sh (100%) rename library/openwrt_slurp.sh => plugins/modules/slurp.sh (100%) rename library/openwrt_stat.sh => plugins/modules/stat.sh (100%) rename library/openwrt_sysctl.sh => plugins/modules/sysctl.sh (100%) rename {library => plugins/modules}/uci.py (100%) rename library/openwrt_uci.sh => plugins/modules/uci.sh (100%) rename {vars_plugins => plugins/vars}/monkeypatch.py (100%) rename {handlers => roles/pkg/handlers}/main.yml (100%) rename tasks/package.yml => roles/pkg/tasks/main.yml (100%) rename tasks/packages.yml => roles/pkg/tasks/recommended.yml (96%) rename {files => roles/prep/files}/wrapper.sh (100%) rename {tasks => roles/prep/tasks}/main.yml (92%) diff --git a/README.md b/README.md index f4769a1..894a01f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -Ansible Role: openwrt -===================== +Ansible Collection: gekmihesg.openwrt +===================================== Manage OpenWRT and derivatives with Ansible but without Python. @@ -26,18 +26,12 @@ Currently, the following modules have been implemented: * uci (new) * wait\_for\_connection (implicit) +# TODO: enable in play with ``collections: [gekmihesg.openwrt]``, reduce need for monkey patch To achieve all this, some monkey patching is involved (in case you wonder about the `vars_plugins`). Compatibility ------------- -This role was tested successfully with: - * LEDE 17.01 (manually) - * OpenWRT 18.06 - * OpenWRT 19.07 - * OpenWRT 21.02 - * OpenWRT 22.03 - Requirements ------------ diff --git a/playbooks/bootstrap.yml b/playbooks/bootstrap.yml new file mode 100644 index 0000000..5951c05 --- /dev/null +++ b/playbooks/bootstrap.yml @@ -0,0 +1,14 @@ +- hosts: openwrt + gather_facts: false + vars_prompt: + - name: openwrt_install_recommended_packages + default: true + - name: openwrt_wait_for_connection + default: true + - name: openwrt_wait_for_connection_timeout + default: 600 + roles: + - prep + tasks: + - name: Ensure we have working setup by using custom fact gathering + gather_facts: diff --git a/defaults/main.yml b/playbooks/group_vars/openwrt.yml similarity index 91% rename from defaults/main.yml rename to playbooks/group_vars/openwrt.yml index 5b8da82..ac72dc0 100644 --- a/defaults/main.yml +++ b/playbooks/group_vars/openwrt.yml @@ -1,6 +1,7 @@ --- -openwrt_install_recommended_packages: true +# group_vars for openwrt group +openwrt_install_recommended_packages: true openwrt_wait_for_connection: true openwrt_wait_for_connection_timeout: 600 @@ -15,3 +16,5 @@ openwrt_ssh_use_tty: false openwrt_remote_tmp: /tmp openwrt_remote_opkg_lists_dir: /tmp/opkg-lists + +ansible_facts_modules: gekmihesg.openwrt.setup diff --git a/library/openwrt_command.sh b/plugins/modules/command.sh similarity index 100% rename from library/openwrt_command.sh rename to plugins/modules/command.sh diff --git a/library/openwrt_copy.sh b/plugins/modules/copy.sh similarity index 100% rename from library/openwrt_copy.sh rename to plugins/modules/copy.sh diff --git a/library/openwrt_file.sh b/plugins/modules/file.sh similarity index 100% rename from library/openwrt_file.sh rename to plugins/modules/file.sh diff --git a/library/openwrt_lineinfile.sh b/plugins/modules/lineinfile.sh similarity index 100% rename from library/openwrt_lineinfile.sh rename to plugins/modules/lineinfile.sh diff --git a/library/nohup.py b/plugins/modules/nohup.py similarity index 100% rename from library/nohup.py rename to plugins/modules/nohup.py diff --git a/library/openwrt_nohup.sh b/plugins/modules/nohup.sh similarity index 100% rename from library/openwrt_nohup.sh rename to plugins/modules/nohup.sh diff --git a/library/openwrt_opkg.sh b/plugins/modules/opkg.sh similarity index 100% rename from library/openwrt_opkg.sh rename to plugins/modules/opkg.sh diff --git a/library/openwrt_ping.sh b/plugins/modules/ping.sh similarity index 100% rename from library/openwrt_ping.sh rename to plugins/modules/ping.sh diff --git a/library/openwrt_service.sh b/plugins/modules/service.sh similarity index 100% rename from library/openwrt_service.sh rename to plugins/modules/service.sh diff --git a/library/openwrt_setup.sh b/plugins/modules/setup.sh similarity index 100% rename from library/openwrt_setup.sh rename to plugins/modules/setup.sh diff --git a/library/openwrt_slurp.sh b/plugins/modules/slurp.sh similarity index 100% rename from library/openwrt_slurp.sh rename to plugins/modules/slurp.sh diff --git a/library/openwrt_stat.sh b/plugins/modules/stat.sh similarity index 100% rename from library/openwrt_stat.sh rename to plugins/modules/stat.sh diff --git a/library/openwrt_sysctl.sh b/plugins/modules/sysctl.sh similarity index 100% rename from library/openwrt_sysctl.sh rename to plugins/modules/sysctl.sh diff --git a/library/uci.py b/plugins/modules/uci.py similarity index 100% rename from library/uci.py rename to plugins/modules/uci.py diff --git a/library/openwrt_uci.sh b/plugins/modules/uci.sh similarity index 100% rename from library/openwrt_uci.sh rename to plugins/modules/uci.sh diff --git a/vars_plugins/monkeypatch.py b/plugins/vars/monkeypatch.py similarity index 100% rename from vars_plugins/monkeypatch.py rename to plugins/vars/monkeypatch.py diff --git a/requirements.txt b/requirements.txt index 7ef2e96..e69de29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +0,0 @@ -molecule[docker,lint] -docker -yamllint -ansible-lint diff --git a/handlers/main.yml b/roles/pkg/handlers/main.yml similarity index 100% rename from handlers/main.yml rename to roles/pkg/handlers/main.yml diff --git a/tasks/package.yml b/roles/pkg/tasks/main.yml similarity index 100% rename from tasks/package.yml rename to roles/pkg/tasks/main.yml diff --git a/tasks/packages.yml b/roles/pkg/tasks/recommended.yml similarity index 96% rename from tasks/packages.yml rename to roles/pkg/tasks/recommended.yml index 2eaaeee..625e8f1 100644 --- a/tasks/packages.yml +++ b/roles/pkg/tasks/recommended.yml @@ -28,7 +28,7 @@ changed_when: false failed_when: false -- include_tasks: package.yml +- include_tasks: main.yml with_dict: base64: coreutils-base64 md5sum: coreutils-md5sum diff --git a/files/wrapper.sh b/roles/prep/files/wrapper.sh similarity index 100% rename from files/wrapper.sh rename to roles/prep/files/wrapper.sh diff --git a/tasks/main.yml b/roles/prep/tasks/main.yml similarity index 92% rename from tasks/main.yml rename to roles/prep/tasks/main.yml index 13180c5..a707dcf 100644 --- a/tasks/main.yml +++ b/roles/prep/tasks/main.yml @@ -14,7 +14,9 @@ tags: always - name: install recommended packages - include_tasks: packages.yml + include_role: + name: pkg + tasks_from: recommended when: - "'openwrt' in group_names" - "openwrt_install_recommended_packages | bool"