-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker_host_info: Filter containers by multiple labels #18
Comments
Files identified in the description: If these files are inaccurate, please update the |
This is the interface provided by Docker itself: it wants a dictionary of filters. If we provide something more sophisticated, we probably have to parse and process this by ourselves. |
But you can actually do that filtering with CLI, right? |
No idea. Feel free to figure out how the CLI does it. |
Definitely the CLI can do it: I think you use docker-py behind the scenes, right? Its docs say you can pass a list to the label fiilter. That would easily map like this to ansible: - name: find running docker containers
register: docker_info
docker_host_info:
containers: yes
containers_filters:
label:
- com.docker.compose.project=myproject
- com.docker.compose.service=backup |
I never claimed the CLI can't do it. I was just stating that I don't know whether it can do it (and honestly, I don't care if it can or not). Feel free to create a PR to implement this. |
@felixfontein, the OP referred to the higher-level API, but the API used by this module does in fact permit a list of labels. Update this to def clean_dict_booleans_for_docker_api(data, allow_sequences=False):
'''
Go doesn't like Python booleans 'True' or 'False', while Ansible is just
fine with them in YAML. As such, they need to be converted in cases where
we pass dictionaries to the Docker API (e.g. docker_network's
driver_options and docker_prune's filters).
'''
result = dict()
if data is not None:
for k, v in data.items():
if allow_sequences and is_sequence(v):
pass
elif v is True:
v = 'true'
elif v is False:
v = 'false'
else:
v = str(v)
result[str(k)] = v
return result |
@Ajpantuso it's a bit more complicated, since the sequence's values have to (potentially) be adjusted as well. Besides that, it should work. |
SUMMARY
Cannot filter for multiple labels.
ISSUE TYPE
COMPONENT NAME
docker_host_info
ADDITIONAL INFORMATION
This cannot work because we can't define the same key twice in a dict:
Possible solutions:
Allow a list in
containers_filters
:Allow a dict in
containers_filters.label
filter:I have not tested, but I guess the same applies to
images_filters
,networks_filters
andvolumes_filters
.The text was updated successfully, but these errors were encountered: