runrole: Accept CLI arguments (and --reinstall flag) in any position - #4146
Conversation
Refactor command-line argument parsing and update logging path handling.
Refactor command-line argument parsing to use a case statement for future extensibility. Shift command is now consistently applied.
--reinstall flag) in any position
Comment out ROLE_NAME and ROLE_VAR initializations.
|
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. |
|
I don't speak fluent bash, I'm more at "conversational level", but I'll give it a look |
| ROLE_NAME="$1" | ||
| export ANSIBLE_LOG_PATH="$CWD/iiab-debug.log" | ||
| else | ||
| export ANSIBLE_LOG_PATH="$1" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
--reinstallmultiple time (as you say, no harm done!)
| shift | ||
| done | ||
|
|
||
| if [ ! -v ROLE_NAME ]; then # Test whether var is STILL not set! |
There was a problem hiding this comment.
And what if it's not? The rest of this script should fail, right?
There was a problem hiding this comment.
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
Refactor role name and log path handling in runrole script.
|
@muthuri-dev can you test this newly refined |
|
@deldesir would you be able to look over this PR quickly? |
|
Testing it right now... |
Sorry "runrole" doesn't do that yet !! |
Rearranged the logging path export to ensure it is set correctly.
|
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@pi500:/opt/iiab/iiab $
jvonau@pi500:/opt/iiab/iiab $ |
|
Thanks @jvonau. Likely a bug that slipped through. I'll take a look. |
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 |
|
there's also runroles, a mini version of running configure in Adm Cons. But the caveat about uninstalling applies I think. |

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/iiabMention a team member @username e.g. to help with code review:
@orblivion @muthuri-dev