Docker Entrypoint

Hi Everyone,

I am trying to convert big old monolith bash script to ansible, and I’m about 90% of the way there.

I am having a bit of trouble with one element, the docker entrypoint.

The original code along with my Ansible attempt and the entrypoint debug output is here: https://pastebin.com/J1j49aKT

I think I have done everything correctly, but I do not get a populated license file

I’m sure there is something glaringly obvious, but I can’t seem to put my finger on it.

Thanks,

Dave

Hi,

I am trying to convert big old monolith bash script to ansible, and
I'm about 90% of the way there.

I am having a bit of trouble with one element, the docker entrypoint.

The original code along with my Ansible attempt and the entrypoint
debug output is here: https://pastebin.com/J1j49aKT

I *think* I have done everything correctly, but I do not get a
populated license file

I'm sure there is something glaringly obvious, but I can't seem to
put my finger on it.

you are relying on the bash shell to quote arguments for you correctly.
Ansible won't do such magic for you.

The `entrypoint` option expects a list of strings; if it is not a list
but a single string, it is treated as a comma-separated concatenated
list, i.e. split by commas. In your case, you end up with a single
string containing the whole command line. This is passed to docker as
the executable to run in your container, which will obviously fail.

You have to compose a proper `entrypoint` list.

Also, the redirect is not part of the thing docker should execut, but
something you have to handle on ansible level (i.e. ask the
docker_container module to capture stdout for you).

Cheers,
Felix

Whoops, upon further scrutiny, I have realised I should be using entrypoint, but command instead.

https://docs.ansible.com/ansible/latest/collections/community/general/docker_container_module.html#parameter-command

Hello,
Sorry if it’s not the right place, I’m thinking my problem is little bit similar.

In guacamole install process, It’s suggest to do:
docker run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh --mysql > initdb.sql

I want to convert in proper way with ansible. This is my task:

  • name: Extract SQL Guacamole
    community.general.docker_container:
    name: guacamole-sql-extract
    image: “guacamole/guacamole:latest”
    container_default_behavior: no_defaults
    command: “/opt/guacamole/bin/initdb.sh --mysql > /srv/live/{{ app_name }}/initdb.sql”

But not file SQL is output.
I tried with container_default_behavior: compatibility, entrypoint instead of command but no more work.

When I tried docker run […] dry, it’s work.

Thanks

Hi,

Sorry if it's not the right place, I'm thinking my problem is little
bit similar.

In guacamole install process, It's suggest to do:
*docker* run --rm guacamole/guacamole /opt/guacamole/bin/initdb.sh
--mysql
> *initdb.sql*

the stdout redirect is NOT part of the command executed by docker. It
is part of the execution of the docker CLI tool itself.

I want to convert in proper way with ansible. This is my task:

- name: Extract SQL Guacamole
community.general.docker_container:
name: guacamole-sql-extract
image: "guacamole/guacamole:latest"
container_default_behavior: no_defaults
command: "/opt/guacamole/bin/initdb.sh --mysql > /srv/live/{{
app_name }}/initdb.sql"

This is wrong. You need to remove the "> /srv/...", and pass the
`detach: false` option to docker_container to enable non-detaching and
stdout capturing. Then you need to register the output of the task, and
extract the output from there as `result.container.Output`.

Also, your command line specifies `--rm`, which is equivalent to
`auto_remove: true`.

Cheers,
Felix

Hello,
Thanks, but without argument, docker ansible failed.

  • name: Extract SQL Guacamole
    community.general.docker_container:
    name: guacamole-sql-extract
    image: “guacamole/guacamole:latest”
    container_default_behavior: no_defaults
    detach: false

command: “/opt/guacamole/bin/initdb.sh --mysql > initdb.sql”

register: sqlextract

And when I let command and detach false, same error :
“msg”: “Wrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\nWrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\nWrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\nWrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\nWrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\nWrong number of arguments.\nUSAGE: /opt/guacamole/bin/initdb.sh [–postgres | --mysql]\n”,
“status”: 1

I have to set command to get work.

May I used volume, but how? Because with dry run docker run, it extract in the folder in argument.

I don’t know… Sorry.