I have got the solution - port forwarding will do the trick. Here are the 
parts of my playbook:

- name: prepare docker container for roles
  hosts: test.server.org

  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
  hosts: test.server.org
  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


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/0b81798a-7e9b-412b-bc3a-099d42319402%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to