简体   繁体   English

Ansible / Rackspace-将多个节点添加到负载均衡器

[英]Ansible/Rackspace - adding multiple nodes to a load balancer

I'm using Ansible to build multiple nodes and then add them to a load balancer. 我正在使用Ansible构建多个节点,然后将它们添加到负载均衡器中。 The issue that arises is that when the second node is being added using the rax_clb_nodes module, I get: 出现的问题是,使用rax_clb_nodes模块添加第二个节点时,我得到:

TASK: [build-servers | add nodes to load balancer] ************************** 
failed: [myserver-v0-0-1-ord -> 127.0.0.1] => {"failed": true}
msg: Load Balancer '123456' has a status of 'PENDING_UPDATE' and is considered immutable.
changed: [myserver-v0-0-1-ord -> 127.0.0.1]

my playbook defines wait=yes and wait_timeout=60 in rax_clb_nodes, so I'm unsure as to why this occurs. 我的剧本在rax_clb_nodes中定义了wait=yeswait_timeout=60 ,所以我不确定为什么会这样。

Any insight into a fix? 对修复有任何见解吗?

This is happening because the rax_clb_nodes task is being executed in parallel on behalf of each matching host in your inventory, but only one load balancer update can be performed at a time. 之所以发生这种情况是因为rax_clb_nodes任务是代表清单中的每个匹配主机并行执行的,但是一次只能执行一次负载均衡器更新。 There are a few approaches to executing it in serial, instead, depending on how your playbooks are organized. 有几种方法可以串行执行它,具体取决于您的剧本的组织方式。

If this task can be easily moved into its own play, use serial: 1 to execute it on behalf of one host at a time instead: 如果可以轻松地将此任务转移到自己的任务中,请使用serial: 1一次代表一个主机执行该任务:

- name: Load balancer membership
  hosts: build-servers
  serial: 1
  tasks:

  - name: Add {{ inventory_hostname }} node to the load balancer
    local_action:
      module: rax_clb_nodes
      address: "{{ rax_addresses.private.0.addr }}"
      port: 443
      state: present
      wait: yes
      wait_timeout: 60
      # ...

Unfortunately, serial can only be specified on entire plays at a time, not individual tasks. 不幸的是, serial只能在整个戏剧在指定的时间,而不是单独的任务。 If the task can't easily be moved to its own play (for example, if it's within a role or in the midst of an included task list), you can achieve serial execution by a combination of run_once and a with_items loop : 如果无法轻松地将任务转移到自己的任务 (例如,如果它在某个角色中或在包含的任务列表中),则可以通过组合run_oncewith_items循环来实现串行执行:

- name: Add nodes to load balancer
  local_action:
    module: rax_clb_nodes
    address: "{{ hostvars[item].rax_addresses.private.0.addr }}"
    port: 443
    state: present
    wait: yes
    wait_timeout: 60
    # ...
  run_once: yes
  with_items: "{{ groups['build-servers'] }}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM