我有一个3节点的docker cluster(swarm),并希望为这些节点分配标签。我当前切换到的节点是节点1,应为其分配标签abc1。其他两个节点应分配为abc2和abc3。
我尝试了https://docs.ansible.com/ansible/devel/modules/docker_node_module.html中给出的示例,但似乎收到YAML语法错误。
我的Yaml:
- name: Assigning labels
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Localhost label assignment
docker_node:
hostname: vm-test
label:
abc1: true
错误:
The offending line appears to be:
tasks:
- name: Localhost label assignment
^ here
使用现有的功能,它将仅将标签分配给节点1。如何将增量标签分别分配给节点2和节点3到abc2和abc3?
hosts文件如下:
[target-machines]
10.xx.xx.xx ansible_sudo_pass=xyz ansible_ssh_pass=xyz ansible_ssh_user=xyz
10.xx.xx.xx ansible_sudo_pass=abc ansible_ssh_pass=abc ansible_ssh_user=abc
有没有办法遍历hosts文件并分配标签?
答案 0 :(得分:3)
此模块在ansible 2.8
中引入。将Ansible升级到2.8,错误就会消失。
pip install ansible==2.8.0rc1
参数哈希为labels
而不是标签。
---
- name: Assigning labels
hosts : localhost
gather_facts: no
connection: local
tasks:
- name: Merge node labels and new labels
docker_node:
hostname: vm-test
labels:
abc1: true