-
Notifications
You must be signed in to change notification settings - Fork 3
Description
I am not able to resolve the variables against the molecule provisioned instance.
Context
I am using vagrant as a molecule driver, so that the connection happens through SSH when molecule executes the playbooks.
However, given the documentation written in README, using the testvars-no-resolvevia-localhost option, I was under the impression that I could choose to run the testvars plugin on the provisioned instance created by molecule, so against the Vagrant box if the vagrant molecule driver was selected, or against the Docker container if the docker molecule driver was selected.
It does not seem to work. Indeed, it will always resolve the variables against localhost. As a proof, right now, testvars['ansible_hostname'] from the Ansible facts will match the host name of the computer executing molecule, so the hostname of your localhost.
Hints
I think I found the reason of the issue: that is because when you used the code from the Ansible documentation about the Ansible API, it hardcoded the use of the local connection plugin.
https://docs.ansible.com/ansible/2.8/dev_guide/developing_api.html
And in those code samples, there was this:
# since the API is constructed for CLI it expects certain options to always be set in the context object
context.CLIARGS = ImmutableDict(connection='local', module_path=['/to/mymodules'], forks=10, become=None,
become_method=None, become_user=None, check=False, diff=False)
which we can found in testaid here:
testaid/testaid/moleculeplay.py
Lines 24 to 31 in 570f37d
| context.CLIARGS = ImmutableDict(connection='local', | |
| module_path=[''], | |
| forks=10, | |
| become=None, | |
| become_method=None, | |
| become_user=None, | |
| check=False, | |
| diff=False) |
Having local in the context here is a showstopper if one needs to connect to the molecule provisioned instance through ssh.
I think that testaid should be able to use the connection plugin used by molecule directly.
Unsuccessful fix
I tried to fix it by just changing local to ssh as it is the name of the default connection plugin, but it ends with an Ansible error:
self = <testaid.ansiblerun.AnsibleRun object at 0x7efc83283710>
play = ansible playbook
def run(self, play):
tqm = None
rc = ResultCallback()
try:
tqm = TaskQueueManager(inventory=self._inventory,
variable_manager=self._variable_manager,
loader=self._loader,
passwords=dict(),
stdout_callback=rc)
tqm.run(play)
finally:
if tqm is not None:
tqm.cleanup()
shutil.rmtree(C.DEFAULT_LOCAL_TMP, True)
if rc.failed_playbook_run:
raise AnsibleRunError(
'Unable to run playbook.',
> rc.result_playbook_run[-1])
E testaid.exceptions.AnsibleRunError: Unable to run playbook.
E Error message: Unexpected failure during module execution.
***/src/testaid/testaid/ansiblerun.py:38: AnsibleRunError
=============================== 3 error in 2.76s ===============================