I have the following situation: I have a remote server that runs docker with a Postgres container. The Postgres instance is only reachable through a docker network, not directly from the remote server.
I am trying to create an ansible role that makes sure all the required databases and users exist in the Postgres instance. For this I am trying to make Ansible first connect to the remote server, then connect to the Postgres docker container, and from there use the
community.postgresql.postgresql_* modules to create the databases and users. However, I am stuck trying to get Ansible to do the nested connection. I currently have the following ansible-playbook:
# playbook.yml - name: Postgres hosts: dockerservers roles: - name: postgres tags: [postgres, never] # roles/postgres/tasks/main.yml - name: Connect to database docker container add_host: name: "postgres" ansible_connection: docker changed_when: false - name: Inside postgres docker container delegate_to: "postgres" block: - name: Debug community.postgresql.postgresql_info:
Docker tries to use the local docker cli (which is not installed) to connect to the remote docker daemon. Is there a way to somehow hop from the remote server to the docker container, instead of trying to directly connect to it?