If you are spinning up docker containers, why don't you use the docker
connection plugin ? I have never used any machintosh so I might miss something, but I don't see why it would not work as expected as long as you can interact with your containers using "normal" docker commands.
Fast POC to get you going.
Inventory inventories/docker-poc.yml
---
all:
children:
my_poc_hosts:
vars:
ansible_connection: docker
hosts:
target1:
target2:
target3:
If you want to keep the ini format, this is the equivalent:
[my_poc_hosts]
target1
target2
target3
[my_poc_hosts:vars]
ansible_connection=docker
Spin up test containers
I used the python:3.8 image (to make sure python is installed as it is mandatory for ansible) with a long running custom command.
for i in {1..3} ; do docker run -d --rm --name target$i python:3.8 sh -c "while true; do sleep 20000; done"; done
Fast test with ad-hoc ping
$ ansible -i inventories/docker-poc.yml my_poc_hosts -m ping
[WARNING]: Platform linux on host target1 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
target1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
[WARNING]: Platform linux on host target3 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
target3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
[WARNING]: Platform linux on host target2 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
target2 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
Cleanup
for i in {1..3}; do docker rm -f target$i; done