ansible: don't crash when adhoc tries to run a missing module.

ansible-playbook prints a separate error during parsing stage, adhoc
performs no such check.
This commit is contained in:
David Wilson 2018-08-10 15:29:42 +01:00
parent 34a9f67115
commit 6c4b01642c
3 changed files with 20 additions and 0 deletions

View File

@ -55,6 +55,7 @@ import ansible_mitogen.target
LOG = logging.getLogger(__name__)
NO_METHOD_MSG = 'Mitogen: no invocation method found for: '
NO_INTERPRETER_MSG = 'module (%s) is missing interpreter line'
NO_MODULE_MSG = 'The module %s was not found in configured module paths.'
class Invocation(object):
@ -393,6 +394,9 @@ _planners = [
def get_module_data(name):
path = ansible_mitogen.loaders.module_loader.find_plugin(name, '')
if path is None:
raise ansible.errors.AnsibleError(NO_MODULE_MSG % (name,))
with open(path, 'rb') as fp:
source = fp.read()
return mitogen.core.to_text(path), source

View File

@ -15,3 +15,4 @@
- import_playbook: environment_isolation.yml
- import_playbook: etc_environment.yml
- import_playbook: forking_behaviour.yml
- import_playbook: missing_module.yml

View File

@ -0,0 +1,15 @@
- name: integration/runner/missing_module.yml
hosts: test-targets
connection: local
tasks:
- connection: local
command: ansible -i localhost, localhost -m missing_module
args:
chdir: ../..
register: out
ignore_errors: true
- assert:
that: |
'The module missing_module was not found in configured module paths.' in out.stdout