cinek810 / ansible-deployer

Command line utility wrapping ansible-playbook to run it with elevated privileges only for certain predefined tasks.
MIT License
4 stars 5 forks source link

Handle situation when "opts" not provided for hook #145

Open LegenJCdary opened 2 years ago

LegenJCdary commented 2 years ago

Traceback (most recent call last): File "/home/fazi/deploy-ans/ansible-deployer/source/modules/runners/run.py", line 41, in setup_ansible with subprocess.Popen([hook["opts"]["file"], commit], KeyError: 'opts'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/fazi/deploy-ans/ansible-deployer/source/main.py", line 174, in main() File "/home/fazi/deploy-ans/ansible-deployer/source/main.py", line 155, in main runner.setup_ansible(selected_items["commit"]) File "/home/fazi/deploy-ans/ansible-deployer/source/modules/runners/run.py", line 49, in setup_ansible self.logger.critical("Failed executing %s: %s", hook["opts"]["file"], e) KeyError: 'opts'

LegenJCdary commented 2 years ago

Best solution would be to make opts and file required when "module" is "script". This cannot be achieved with cerberus in straight-forward way, dedicated Validator needs to be written and imported e.g. https://stackoverflow.com/questions/56705509/dependencies-validation-using-cerberus