From 5e737e0009c087968932a749c6942cc04bf8580c Mon Sep 17 00:00:00 2001 From: Mathieu Bultel Date: Fri, 28 Sep 2018 16:01:39 +0200 Subject: [PATCH] Use subnodes groups for multinode roles and templates Instead of looping on 'all' nodes, restricting the loop to only subnodes groups avoid failure if other hosts is present. Change-Id: Ife744d89836af2c98bffe5ae10f8544625ed9f2b --- roles/multinodes/tasks/main.yml | 8 ++++---- roles/multinodes/templates/multinode_hosts.j2 | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/roles/multinodes/tasks/main.yml b/roles/multinodes/tasks/main.yml index a8dd2cbf2..3bc8f5c49 100644 --- a/roles/multinodes/tasks/main.yml +++ b/roles/multinodes/tasks/main.yml @@ -144,7 +144,7 @@ retries: 100 delay: 5 with_items: - - "{{ hostvars.keys() }}" + - "{{ groups['subnodes'] }}" # In case of blank centos image we need to create CI user and update inventory - block: @@ -157,7 +157,7 @@ become: true delegate_to: "{{ item}}" with_items: - - "{{ hostvars.keys() }}" + - "{{ groups['subnodes'] }}" - name: Setup keys authorized_key: @@ -168,7 +168,7 @@ become_user: "{{ nodepool_user }}" delegate_to: "{{ item}}" with_items: - - "{{ hostvars.keys() }}" + - "{{ groups['subnodes'] }}" - name: Allow user to have passwordless sudo lineinfile: @@ -179,7 +179,7 @@ become: true delegate_to: "{{ item}}" with_items: - - "{{ hostvars.keys() }}" + - "{{ groups['subnodes'] }}" - name: Add hosts add_host: diff --git a/roles/multinodes/templates/multinode_hosts.j2 b/roles/multinodes/templates/multinode_hosts.j2 index 05f0339ff..820cb2ef7 100644 --- a/roles/multinodes/templates/multinode_hosts.j2 +++ b/roles/multinodes/templates/multinode_hosts.j2 @@ -1,4 +1,4 @@ -{% for h in groups['all'] %} +{% for h in groups['subnodes'] %} {{ h }} ansible_host={{ hostvars[h].ansible_host }} ansible_user={{ hostvars[h].ansible_user }} ansible_private_key_file={{ hostvars[h].ansible_private_key_file }}{% if hostvars[h].get('subnode_private_ip') %} subnode_private_ip={{ hostvars[h].subnode_private_ip }}{% endif %}{% if hostvars[h].get('subnode_public_ip') %} subnode_public_ip={{ hostvars[h].subnode_public_ip }}{% endif %} {% endfor %}