gpt4 book ai didi

Docker_swarm 模块 - ansible 的 join_token 参数不起作用

转载 作者:行者123 更新时间:2023-12-02 18:05:55 25 4
gpt4 key购买 nike

这是我的 ansible 剧本,任务是从 docker_swarm 模块文档中复制的,所以它应该可以工作:

  - name: Init a new swarm with default parameters
docker_swarm:
state: present
advertise_addr: "{{ manager_ip }}:2377"
register: rezult
when: "ansible_default_ipv4.address == '{{ manager_ip }}'"


- name: Add nodes
docker_swarm:
state: join
advertise_addr: "{{ manager_ip }}"
join_token: rezult.swarm_facts.JoinTokens.Worker
remote_addrs: "{{ manager_ip }}:2377"
when: "ansible_default_ipv4.address != '{{ manager_ip }}'"

它使用“manager_ip”--extra-var 初始化一个集群管理器
但它在“添加节点任务”中失败并出现以下错误:
fatal: [vm2]: FAILED! => {"changed": false, "msg": "Can not join the Swarm Cluster: 500 Server Error: Internal Server Error (\"invalid join token\")"}

如果我在 join_token 之后将 "'{{ }}'"放在 "rezult.swarm_facts.JoinTokens.Worker"周围,我会得到:
fatal: [vm2]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'swarm_facts'\n\nThe error appears to be in '/home/ansible/docker-ansible/docker.yml': line 47, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - name: Add nodes\n    ^ here\n"}

如果我将调试消息放入 rezult.swarm_facts.JoinTokens.Worker 我得到正确的 token :
ok: [opensuse1] => {
"msg": "SWMTKN-1-5p7brhxxz4gzu716t78tt5woj7h6aflq0kdwvzwlbbe7ct0ba7-e59bg0t79q67ogd61ydwxc5yq"
}

如果我在服务器上通过 docker swarm join 命令手动使用该 token ,我希望与管理器合并它可以工作。因此变量具有正确的值并且节点之间的连接起作用。但我就是无法让 join_token 工作。我正在使用 python 2.7.5 运行 ansible 2.8.5。

我知道我可以使用 shell 模块,但我不想这样做。

最佳答案

像这样的东西对我有用:

---
- name: Init swarm on the first node
community.general.docker_swarm:
state: present
advertise_addr: "{{ ansible_host }}"
register: result
when: inventory_hostname == groups['swarm_managers'][0]

- name: Get join-token for manager nodes
set_fact:
join_token_manager: "{{ hostvars[groups['swarm_managers'][0]].result.swarm_facts.JoinTokens.Manager }}"

- name: Get join-token for worker nodes
set_fact:
join_token_worker: "{{ hostvars[groups['swarm_managers'][0]].result.swarm_facts.JoinTokens.Worker }}"

- name: Join other managers
community.general.docker_swarm:
state: join
join_token: "{{ join_token_manager }}"
advertise_addr: "{{ ansible_host }}"
remote_addrs: "{{ hostvars[groups['swarm_managers'][0]].ansible_host }}"
when:
- inventory_hostname in groups['swarm_managers']
- inventory_hostname != groups['swarm_managers'][0]

- name: Join workers
community.general.docker_swarm:
state: join
join_token: "{{ join_token_worker }}"
advertise_addr: "{{ ansible_host }}"
remote_addrs: "{{ hostvars[groups['swarm_managers'][0]].ansible_host }}"
when:
- inventory_hostname not in groups['swarm_managers']
swarm_managers组中有经理,并且此 list 中的所有其他主机都是 worker 。

关于Docker_swarm 模块 - ansible 的 join_token 参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58232506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com