diff --git a/defaults/main.yml b/defaults/main.yml index 20f45a9..2a63f0c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -34,3 +34,10 @@ docker_log_to_journal: True docker_daemon_debug: False docker_prometheus_metrics: True docker_prometheus_host: 127.0.0.1 + +# merge, replace +docker_label_state_mode: merge +docker_node_labels: [] +#docker_node_labels: +# - { key: 'key_name', value: 'label_value' } + diff --git a/tasks/swarm_node.yml b/tasks/swarm_node.yml index d260d64..ef7be26 100644 --- a/tasks/swarm_node.yml +++ b/tasks/swarm_node.yml @@ -41,3 +41,17 @@ when: docker_swarm_node | bool delegate_to: '{{ docker_swarm_manager_main_node_hostname }}' tags: [ 'docker', 'docker_swarm', 'docker_swarm_worker_nodes', 'docker_swarm_worker_nodes_availability' ] + +- name: Manage labels + block: + - name: Manage the swarm nodes labels + docker_node: + hostname: '{{ ansible_hostname }}' + labels: + '{{ item.key }}': '{{ item.value }}' + labels_state: '{{ docker_label_state_mode }}' + with_items: '{{ docker_node_labels }}' + + when: docker_swarm_node | bool + delegate_to: '{{ docker_swarm_manager_main_node_hostname }}' + tags: [ 'docker', 'docker_swarm', 'docker_swarm_worker_nodes', 'docker_nodes_labels' ]