- name: prepare docker container for roles
tasks:
...
- name: create client container
sudo: yes
docker:
image: my_ssh_container
name: test_container
detach: False
state: running
- name: create connection string
set_fact:
connection_command: "ssh -p {{ ansible_ssh_port }} -f -N -L 3456:{{ docker_containers[0].NetworkSettings.IPAddress }}:22 {{ ansible_ssh_user}}@{{ ansible_ssh_host }}"
- name: create local port forwarding to remote docker container
command: "{{ connection_command }}"
delegate_to: localhost
- name: run roles inside the client container
hosts: docker_container_tunnel
# SET VARIABLE HERE!
roles:
- { role: thomass.java }
- name: quit ssh tunnel
tasks:
- name: recreate connection string
set_fact:
connection_command: "ssh -p {{ ansible_ssh_port }} -f -N -L 3456:{{ docker_containers[0].NetworkSettings.IPAddress }}:22 {{ ansible_ssh_user}}@{{ ansible_ssh_host }}"
- name: destroy local port forwarding to remote docker container
command: "pkill -f \"{{ connection_command }}\""
delegate_to: localhost