I'm having an issue here with the ansible docker_container command.
- name: Start Docker
docker_container:
name: postgres
image: "centos/postgresql-94-centos7"
state: started
recreate: yes
pull: yes
env:
POSTGRESQL_USER: "test"
POSTGRESQL_PASSWORD: "test"
POSTGRESQL_DATABASE: "test"
POSTGRESQL_MAX_CONNECTIONS: 100
POSTGRESQL_SHARED_BUFFERS: 32M
exposed_ports:
- 5432
ports:
- 5432:5432
become: yes
become_method: sudo
When this command runs, it boots the container, but the container immediately exits with some output that I can't see because ansible doesn't print sys out for that for some reason.
Here's an example of some output that is printed when the container refuses to boot (due to incorrect config):
$ sudo docker run --name postgres -e POSTGRESQL_USER="test" -p 5432:5432 centos/postgresql-94-centos7
You must either specify the following environment variables:
POSTGRESQL_USER (regex: '^[a-zA-Z_][a-zA-Z0-9_]*$')
POSTGRESQL_PASSWORD (regex: '^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$')
POSTGRESQL_DATABASE (regex: '^[a-zA-Z_][a-zA-Z0-9_]*$')
Or the following environment variable:
POSTGRESQL_ADMIN_PASSWORD (regex: '^[a-zA-Z0-9_~!@#$%^&*()-=<>,.?;:|]+$')
Or both.
Optional settings:
POSTGRESQL_MAX_CONNECTIONS (default: 100)
POSTGRESQL_MAX_PREPARED_TRANSACTIONS (default: 0)
POSTGRESQL_SHARED_BUFFERS (default: 32MB)
For more information see /usr/share/container-scripts/postgresql/README.md
within the container or visit https://github.com/openshift/postgresql.
This is the output that I do not see when I run it from ansible, it just says its up (success) and then I check docker ps and its not up because presumably it immediately exited. What's more weird is that I can get this to work just fine with the same configuration passed to the ansible command module, but with the docker_container maybe its not passing the env correctly? I'm really not sure because I can't even get the error output.
Check
docker ps -a
to see if ansible managed to at least create the container. If it did, check
docker logs postgres
Hopefully that should give you a clue where it's failing. If you're confused with that maybe you can post some of the (redacted) logs to show where it's failing?