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
This commit is contained in:
Logan V
2016-09-01 14:44:20 -05:00
parent 8cc6364d40
commit e2341fcd69
2 changed files with 13 additions and 11 deletions

View File

@@ -18,17 +18,19 @@
connection: local connection: local
gather_facts: false gather_facts: false
tasks: tasks:
- set_fact: - name: Create known container hosts fact
_container_hosts: > set_fact:
{%- for item in groups['all_containers'] -%} _known_container_hosts: >
{%- if hostvars[item]['physical_host'] | default(false) != item -%} {% set _var = [] -%}
{{ hostvars[item]['physical_host'] }}{% if not loop.last %},{% endif %} {% for item in groups['all_containers'] -%}
{%- endif -%} {% if hostvars[item]['physical_host'] | default(false) != item -%}
{%- endfor -%} {% if _var.append(hostvars[item]['physical_host']) -%}
- set_fact: {% endif -%}
_known_container_hosts: "{{ _container_hosts | replace('\n', '') }}" {% endif -%}
{% endfor -%}
{{ _var | unique }}
- name: Create dynamic lxc_host group - name: Create dynamic lxc_host group
add_host: add_host:
hostname: "{{ item }}" hostname: "{{ item }}"
groups: "known_container_hosts" groups: "known_container_hosts"
with_items: "{{ _known_container_hosts.split(',') | unique }}" with_items: "{{ _known_container_hosts }}"

View File

@@ -16,7 +16,7 @@
- include: common-plays/generate-lxc-container-hosts.yml - include: common-plays/generate-lxc-container-hosts.yml
- name: Basic lxc host setup - name: Basic lxc host setup
hosts: known_container_hosts hosts: "{{ lxc_host_group | default('known_container_hosts') }}"
gather_facts: "{{ gather_facts | default(True) }}" gather_facts: "{{ gather_facts | default(True) }}"
max_fail_percentage: 20 max_fail_percentage: 20
user: root user: root