Search code examples
dockermacosansibleapple-m1

Ansible connection to docker engine on osx apple Silicon


I'm trying to connect to my local docker engine running on OSX (m1 chip) in order to create a dynamic inventory. I've created a host file with the following config I made sure that docker_containers module is well installed.

plugin: community.docker.docker_containers
docker_host: "unix://Users/ME/.docker/run/docker-cli-api.sock"

Then I run ansible-inventory --graph -i ./hosts/hosts-docker-local.yaml.

But I'm getting the following error:

[WARNING]:  * Failed to parse /Users/ME/Projects/ansible-test/hosts/hosts-docker-local.yaml with auto plugin: inventory source '/Users/ME/Projects/ansible-test/hosts/hosts-docker-local.yaml' could not be
verified by inventory plugin 'community.docker.docker_containers'
[WARNING]:  * Failed to parse /Users/ME/Projects/ansible-test/hosts/hosts-docker-local.yaml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]:  * Failed to parse /Users/ME/Projects/ansible-test/hosts/hosts-docker-local.yaml with ini plugin: Invalid host pattern 'plugin:' supplied, ending in ':' is not allowed, this character is reserved to
provide a port.
[WARNING]: Unable to parse /Users/ME/Projects/ansible-test/hosts/hosts-docker-local.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
@all:
  |--@ungrouped:

I tried

 ansible-doc -t inventory -l  | grep docker
community.docker.docker_containers                      Ansible dynamic inv...
community.docker.docker_machine                         Docker Machine inve...
community.docker.docker_swarm                           Ansible dynamic inv...

but somehow if I do this ansible localhost -i ./hosts/hosts-docker-local.yaml -m community.docker.docker_containers

It complains

localhost | FAILED! => {
    "msg": "The module community.docker.docker_containers was not found in configured module paths"
}

maybe something wrong with my module path, something wierd with OSX? (I installed Ansible with brew) 



Solution

  • The inventory file must end in docker.yaml, as pointed out by @Zeitounator.

    Uses a YAML configuration file that ends with docker.[yml|yaml].

    https://docs.ansible.com/ansible/latest/collections/community/docker/docker_containers_inventory.html#synopsis