Skip to content
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

Can't find any examples where docker_* modules are used together #539

Open
cen1 opened this issue Dec 29, 2022 · 1 comment
Open

Can't find any examples where docker_* modules are used together #539

cen1 opened this issue Dec 29, 2022 · 1 comment
Labels
docker-swarm Docker Swarm documentation Improvements or additions to documentation

Comments

@cen1
Copy link

cen1 commented Dec 29, 2022

SUMMARY

I can't find any examples in the documentation how to combine modules together. Specifically,

  1. Init swarm
  2. Add some labels to each node

While docker_swarm runs on the ansible host, docker_node by default connects to local docker. docker_swarm does not register any cluster information which I could use in docker_node so I assume an intermediate task docker_swarm_info is needed to get the node list and then iterate over that list. However, docker_swarm_info also requires a docker_host param to connect to the cluster. I think? using ansible_host should do it, but then I also need to have conditionals for manager node.. but I only need to set the labels once so I probably just need a single task that connects on the manager n.o. 1 and skip all other hosts..

A simple straightforward example in the docs would be really nice.

ISSUE TYPE
  • Documentation Report
COMPONENT NAME
  • docker_swarm
  • docker_swarm_info
  • docker_node
@felixfontein felixfontein added the documentation Improvements or additions to documentation label Dec 29, 2022
@cen1 cen1 changed the title Can't find any examples wher docker_* modules are used together Can't find any examples where docker_* modules are used together Dec 29, 2022
@felixfontein felixfontein added the docker-swarm Docker Swarm label Dec 29, 2022
@cen1
Copy link
Author

cen1 commented Dec 29, 2022

This is the best I could come up with. Not including docker_swarm since it does not really contribute to the end goal.

- name: Get list of nodes in Docker Swarm
  docker_swarm_info:
    nodes: true
  register: docker_swarm_info
  when: inventory_hostname in groups['managers'][0]

- name: Add node labels
  docker_node:
    labels_state: replace
    hostname: "{{ item.ID }}"
    labels:
      mykey: mylabel
  loop: "{{ hostvars[groups['managers'][0]]['docker_swarm_info']['nodes'] }}"
  when: inventory_hostname in groups['managers'][0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker-swarm Docker Swarm documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants