Skip to content

runrole: Accept CLI arguments (and --reinstall flag) in any position - #4146

Merged
holta merged 5 commits into
iiab:masterfrom
holta:runrole-better
Nov 14, 2025
Merged

holta merged 5 commits into
iiab:masterfrom
holta:runrole-better

Conversation

@holta

@holta holta commented Nov 13, 2025 •

Copy link
Copy Markdown
Member

Fixes bug:

Description of changes proposed in this pull request:

Refactor command-line argument parsing and update logging path handling.

Smoke-tested on which OS or OS's:

Ubuntu 26.04 (latest pre-release) but needs more testing! @muthuri-dev can you help?

Please see https://FAQ.IIAB.IO for an explanation (& examples) on how to use the ./runrole <IIAB ROLE> command (as root!) after you run: cd /opt/iiab/iiab

Mention a team member @username e.g. to help with code review:

@orblivion @muthuri-dev

Refactor command-line argument parsing and update logging path handling.
@holta holta added this to the 8.3 milestone Nov 13, 2025
Refactor command-line argument parsing to use a case statement for future extensibility. Shift command is now consistently applied.
@holta holta changed the title runrole: Accept CLI arguments in any position runrole: Accept CLI arguments (and --reinstall flag) in any position Nov 13, 2025
Comment out ROLE_NAME and ROLE_VAR initializations.
@holta
holta marked this pull request as ready for review November 13, 2025 07:12
@orblivion

Copy link
Copy Markdown
Contributor

Just for consideration - I wonder how much this actually bothers people, vs the risk of bug and added complication to the code. I don't think I ever got this wrong myself in the shell, I just typed it wrong in a github comment. Also, at a certain point it may be worth just writing in python? Just for the argument parsing.

@orblivion

Copy link
Copy Markdown
Contributor

I don't speak fluent bash, I'm more at "conversational level", but I'll give it a look

Comment thread runrole
ROLE_NAME="$1"
export ANSIBLE_LOG_PATH="$CWD/iiab-debug.log"
else
export ANSIBLE_LOG_PATH="$1"

@orblivion orblivion Nov 13, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this goes ./runrole ROLE_NAME ANSIBLE_LOG_PATH where ANSIBLE_LOG_PATH is optional and --reinstall can be stuck in anywhere after ./runrole?

If that's right, maybe you could assert (with a "too many arguments" failure) that ANSIBLE_LOG_PATH is not already set. The way it is now, you could have extra arguments that don't do anything and it only takes the last arg as ANSIBLE_LOG_PATH. It wouldn't break anything but maybe you could "fail fast" for the benefit of someone who accidentally put in an extra argument.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: only hard-core implementers use ./runrole but I agree with the spirit...

  • So now it will at least warn people who blindly try ./runrole <ROLE1> <ROLE2> <ROLE3>

  • Though I'm not going to worry about users who specify --reinstall multiple time (as you say, no harm done!)

Comment thread runrole
shift
done

if [ ! -v ROLE_NAME ]; then # Test whether var is STILL not set!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what if it's not? The rest of this script should fail, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, this is the fail! (exit 0). Though, should it be exit 1?

> rmdir
rmdir: missing operand
Try 'rmdir --help' for more information.
> echo $?
1

@holta

holta commented Nov 13, 2025

Copy link
Copy Markdown
Member Author

@muthuri-dev can you test this newly refined ./runrole <ROLE> command after it's merged — even if you cannot today?!

@holta

holta commented Nov 14, 2025

Copy link
Copy Markdown
Member Author

@deldesir would you be able to look over this PR quickly?

@holta
holta requested a review from deldesir November 14, 2025 00:42
@deldesir

Copy link
Copy Markdown
Member

Testing it right now...

@deldesir deldesir left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smoke tested on U25.10. Does the job.

@deldesir

deldesir commented Nov 14, 2025 •

Copy link
Copy Markdown
Member

TIL I can run 1+ roles in a single run!

image

UPDATE: Only the first one (Calibre-Web) ran...

@holta

holta commented Nov 14, 2025

Copy link
Copy Markdown
Member Author

TIL I can run 1+ roles in a single run!

Sorry "runrole" doesn't do that yet !!

@holta
holta merged commit 00d6aec into iiab:master Nov 14, 2025
4 of 5 checks passed
holta added a commit that referenced this pull request Nov 15, 2025
Rearranged the logging path export to ensure it is set correctly.
@jvonau

jvonau commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

Where did the log file go to?

@holta

holta commented Nov 18, 2025

Copy link
Copy Markdown
Member Author

Where did the log file go to?

Log file should be in the same place as before.

Is there a bug or specific failure?

@jvonau

jvonau commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

jvonau@pi500:/opt/iiab/iiab $ sudo git pull origin master
remote: Enumerating objects: 75, done.
remote: Counting objects: 100% (65/65), done.
remote: Compressing objects: 100% (42/42), done.
remote: Total 75 (delta 37), reused 46 (delta 23), pack-reused 10 (from 2)
Unpacking objects: 100% (75/75), 29.17 KiB | 807.00 KiB/s, done.
From https://github.com/iiab/iiab

  • branch master -> FETCH_HEAD
    985d024..272ae8c master -> origin/master
    Updating 985d024..272ae8c
    Fast-forward
    roles/kiwix/templates/iiab-make-kiwix-lib | 2 +-
    roles/kiwix/templates/iiab-make-kiwix-lib3.py | 13 +++++++++----
    roles/maps/README.md | 38 +++++++++++++++++++++++++++++++++++++-
    runrole | 59 ++++++++++++++++++++++++++++++++++++++---------------------
    vars/local_vars_android.yml | 35 +++++++++++++++++++++++++++++++++++
    5 files changed, 120 insertions(+), 27 deletions(-)
    create mode 100644 vars/local_vars_android.yml

jvonau@pi500:/opt/iiab/iiab $ ls
ansible.cfg iiab-debug.log iiab-network install-support.yml.unused run-one-role.yml tests.unused
ansible_hosts iiab-from-cmdline.yml iiab-network.log LICENSE runrole test.yml
collections.yml iiab-from-console.yml iiab-network.yml LICENSING.md runroles unmaintained-roles.txt
CONTRIBUTING.md iiab-install iiab-setup README.md runroles-base.yml vars
iiab-configure iiab-install.log iiab-stages.yml roles scripts
jvonau@pi500:/opt/iiab/iiab $ sudo mv iiab-debug.log iiab-debug.log.old
jvonau@pi500:/opt/iiab/iiab $ sudo ./runrole bluetooth
jvonau@pi500:/opt/iiab/iiab $ ls
ansible.cfg iiab-debug.log.old iiab-network install-support.yml.unused run-one-role.yml tests.unused
ansible_hosts iiab-from-cmdline.yml iiab-network.log LICENSE runrole test.yml
collections.yml iiab-from-console.yml iiab-network.yml LICENSING.md runroles unmaintained-roles.txt
CONTRIBUTING.md iiab-install iiab-setup README.md runroles-base.yml vars
iiab-configure iiab-install.log iiab-stages.yml roles scripts

@holta

holta commented Nov 18, 2025

Copy link
Copy Markdown
Member Author

Thanks @jvonau. Likely a bug that slipped through. I'll take a look.

@jvonau

jvonau commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

TIL I can run 1+ roles in a single run!
UPDATE: Only the first one (Calibre-Web) ran...

If you want to run multiple roles I suggest using iiab-configure but a reinstall would require removing the role from /etc/iiab/iiab_state.yml by hand something that was addressed 5 years ago within #2500, the companion iiab/iiab-factory#134 and related #2771

@tim-moody

Copy link
Copy Markdown
Contributor

there's also runroles, a mini version of running configure in Adm Cons. But the caveat about uninstalling applies I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants