From e2341fcd69d1518b6ae196147ddbe5049f1ad06a Mon Sep 17 00:00:00 2001 From: Logan V Date: Thu, 1 Sep 2016 14:44:20 -0500 Subject: [PATCH] Optimize and fix known container hosts group 1) Optimizes the generation of the known container hosts list. 2) Re-add the "lxc_host_group" operator override var which was accidentally removed in I99eb876f1d089a73ae162f5629422dc492a99d09. Change-Id: Ifb995bd29a62d81f6e5683f3cd1a49077cdbb035 --- .../generate-lxc-container-hosts.yml | 22 ++++++++++--------- playbooks/lxc-hosts-setup.yml | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/playbooks/common-plays/generate-lxc-container-hosts.yml b/playbooks/common-plays/generate-lxc-container-hosts.yml index 15a9c70125..1b65960f26 100644 --- a/playbooks/common-plays/generate-lxc-container-hosts.yml +++ b/playbooks/common-plays/generate-lxc-container-hosts.yml @@ -18,17 +18,19 @@ connection: local gather_facts: false tasks: - - set_fact: - _container_hosts: > - {%- for item in groups['all_containers'] -%} - {%- if hostvars[item]['physical_host'] | default(false) != item -%} - {{ hostvars[item]['physical_host'] }}{% if not loop.last %},{% endif %} - {%- endif -%} - {%- endfor -%} - - set_fact: - _known_container_hosts: "{{ _container_hosts | replace('\n', '') }}" + - name: Create known container hosts fact + set_fact: + _known_container_hosts: > + {% set _var = [] -%} + {% for item in groups['all_containers'] -%} + {% if hostvars[item]['physical_host'] | default(false) != item -%} + {% if _var.append(hostvars[item]['physical_host']) -%} + {% endif -%} + {% endif -%} + {% endfor -%} + {{ _var | unique }} - name: Create dynamic lxc_host group add_host: hostname: "{{ item }}" groups: "known_container_hosts" - with_items: "{{ _known_container_hosts.split(',') | unique }}" + with_items: "{{ _known_container_hosts }}" diff --git a/playbooks/lxc-hosts-setup.yml b/playbooks/lxc-hosts-setup.yml index bda779f942..08068d83aa 100644 --- a/playbooks/lxc-hosts-setup.yml +++ b/playbooks/lxc-hosts-setup.yml @@ -16,7 +16,7 @@ - include: common-plays/generate-lxc-container-hosts.yml - name: Basic lxc host setup - hosts: known_container_hosts + hosts: "{{ lxc_host_group | default('known_container_hosts') }}" gather_facts: "{{ gather_facts | default(True) }}" max_fail_percentage: 20 user: root