Under certain conditions, Ansible is unable to detect the correct OPAC/Staff interface port
When creating a new Sandbox instance with ansible/create-sandbox-instance.yml,
we execute three Ansible tasks responsible for detecting the exposed port numbers
for the Staff interface, OPAC, and OpenSSH server running inside the Koha container.
This information is later used in the instance's Apache configuration in order to
set the ProxyPass and ProxyPassReverse directives for each <VirtualHost>.
There's an edge case, however, where this code might not work as intended.
The Ansible tasks in question use a combination of the docker port, grep, rev
and cut commands to figure out which Docker port to redirect to.
The problem arises in the rare case where the exposed Docker ports contain either
the number 8080 or 8081.
Consider, for example, the following scenario:
$ docker port koha-unimarc
22/tcp -> 0.0.0.0:38078
8080/tcp -> 0.0.0.0:38079
8081/tcp -> 0.0.0.0:38080
greping for 8080 won't work as expected, as it will return not
one but two lines of output. Eventually, the docker_port_opac variable will
contain the string 38079\n38080 which is obviously not a correct port number
to redirect to.
The solution is to pass the port/protocol as a parameter in the docker port command, like so:
$ docker port koha-unimarc 8080/tcp
0.0.0.0:38079
I have a patch in the works, so expect a Merge request soon!