community.docker.docker_login issue

1,428 views
Skip to first unread message

William Flow

unread,
Jun 28, 2023, 4:29:28 PM6/28/23
to Ansible Project
so bottom line I am using the community.docker collection and my code is pretty simple to start I just want to login to my registry and i am failing and do not have 
a clue as to why my code is below and I get this error

{
  "msg": "Error connecting: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))",
  "invocation": {
    "module_args": {
      "registry_url": "registry.hub.docker.com",
      "username": "xxxxxxxxx",
      "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
      "reauthorize": true,
      "docker_host": "unix://var/run/docker.sock",
      "api_version": "auto",
      "timeout": 60,
      "tls": false,
      "use_ssh_client": false,
      "validate_certs": false,
      "debug": false,
      "state": "present",
      "config_path": "/root/.docker/config.json",
      "tls_hostname": null,
      "ca_cert": null,
      "client_cert": null,
      "client_key": null,
      "ssl_version": null
    }
  },
  "_ansible_no_log": null,
  "changed": false
}


---
- name: docker
  hosts: localhost
  gather_facts: false
  collections:
    - community.docker

  - name: Docker Login
      community.docker.docker_login:
        registry_url: registry.hub.docker.com
        username: xxxxxxxxx
        password: XXXXXXXXX

Andrew Latham

unread,
Jun 28, 2023, 4:36:44 PM6/28/23
to ansible...@googlegroups.com
The default url is correct, why are you setting it to that address?

registry_url string The registry URL. Default: "https://index.docker.io/v1/"


via CLI
$ docker info | grep Registry
Registry: https://index.docker.io/v1/


--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f6565b9c-9641-489a-898f-ad941a91c819n%40googlegroups.com.


--
- Andrew "lathama" Latham -

Felix Fontein

unread,
Jun 28, 2023, 4:40:26 PM6/28/23
to ansible...@googlegroups.com
Hi William,

> so bottom line I am using the community.docker collection and my code
> is pretty simple to start I just want to login to my registry and i
> am failing and do not have
> a clue as to why my code is below and I get this error
>
> {
> "msg": "Error connecting: Error while fetching server API version:
> ('Connection aborted.', FileNotFoundError(2, 'No such file or
> directory'))", "invocation": {

the error says that the module cannot talk to your Docker daemon.

You didn't configure any way to talk to the Daemon, so the default is
used, which means using a Unix socket /var/run/docker.sock.

When trying to access /var/run/docker.sock, a FileNotFoundError error
was raised.

You can probably resolve this by telling the module how to connect to
your Docker daemon. (The most easy way to do that is to use the
community.docker.docker module defaults group, then you only have to do
it once for all modules in your play. Alternatively you can use
environment variables, which should work fine for localhost - it's more
tricky on remote hosts.)

Cheers,
Felix

William Flow

unread,
Jun 28, 2023, 5:15:03 PM6/28/23
to Ansible Project
Ok that worked but I now keep getting a new error when I go to task 2:

 - name: run command
      community.docker.docker_container_exec:
        container: ubuntu
        command: /bin/bash -c "ls -lah"
        chdir: /root
      register: result

    - name: Print stdout
      debug:
        msg: '{{result}}'

I get this:
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Could not find container \"ubuntu\""}

am i suppose to pull it not sure here




Thanks 


Bill

Felix Fontein

unread,
Jun 29, 2023, 12:46:06 AM6/29/23
to ansible...@googlegroups.com
Hi,

does `docker container list` show a container with name `ubuntu`? If
not, the error message is completely accurate. The
docker_container_exec module does something similar to `docker exec -w
/root ubuntu /bin/bash -c "ls -lah"`.

If you don't have a container called `ubuntu`, you first have to start
one so you can run a command in it. Or alternative, use the
docker_container module to create a new container and run that command
directly in it (with `detach: false`).

Cheers,
Felix
Reply all
Reply to author
Forward
0 new messages