ansible --version: ansible 2.4.2.0
molecule --version: molecule, version 2.5.0
I am testing a role called: ansible-role-redmine. This role depends on bngsudheer.ruby. I have my dependency like this in molecule.yml:
dependency:
name: galaxy
options:
role-file: requirements.yml
ignore-errors: false
This is my playbook.yml:
- name: Converge
hosts: all
roles:
- bngsudheer.ruby
- ansible-role-redmine
The problem I ran into is this: when the ansible-role-redmine starts running, it won't have access to the desired ruby version because /etc/profile.d/enableruby24.sh is not loaded into current login session. Is it possible to somehow reset the Ansible connection to docker container so that the session is forced to reset thus enabling /etc/profile.d/enableruby24.sh for the remaining tasks in the role?
I tried running source /etc/profile.d/enableruby24.sh via shell module and it didn't work.
Would it work if you did?
- name: Converge the ruby role
hosts: all
roles:
- bngsudheer.ruby
- name: Converge the redmine role
hosts: all
roles:
- ansible-role-redmine
This did not work, unfortunately. Looks like Ansible maintains the same connection because the user and host is same in both the plays.
I think stopping and starting the container instance in a pre-task will solve my problem. Is it possible to do something like that?
I have no idea. Not really a use case I can help you with.
@bngsudheer Did you try the reset_connection action of the meta module?
http://docs.ansible.com/ansible/latest/meta_module.html
The docs specifically refer to resetting an _ssh_ connection, so it might not work, but maybe worth a shot.
FWIW, I'm not convinced that restarting the connection to the container is the _best_ approach. Would it be possible to modify the redmine role to not rely on the PATH's environment variable's ruby? Maybe you could tell redmine to use a ruby version by absolute path, perhaps passed as an Ansible variable?
Good suggestions @elliotweiser. Either way, this isn't really a Molecule issue to solve.
@elliotweiser thanks. I already tried reset_connection. Unfortunately, that meta has a bug
I tried to workaround it by restarting container.
I agree that is a more elegant solution. I will look for a fix in that module.
Thanks for the help.
Closing, not much can be done here.
Most helpful comment
@bngsudheer Did you try the
reset_connectionaction of themetamodule?http://docs.ansible.com/ansible/latest/meta_module.html
The docs specifically refer to resetting an _ssh_ connection, so it might not work, but maybe worth a shot.
FWIW, I'm not convinced that restarting the connection to the container is the _best_ approach. Would it be possible to modify the redmine role to not rely on the
PATH's environment variable's ruby? Maybe you could tell redmine to use a ruby version by absolute path, perhaps passed as an Ansible variable?