From d48deac395d32d47f5bf916d63092376f967b96e Mon Sep 17 00:00:00 2001 From: Jiri Podivin Date: Thu, 10 Mar 2022 10:00:27 +0100 Subject: [PATCH] Explicitly naming variable to eliminate possible collision The ansible loop construct assigns the same variable name 'item' to all loops by default. This can lead to potential name space collisions, as multiple loops, operating over different datastructures, can be nested within each other, and potentially modify each others data. Introduction of a named loop variable prevents this, unlikely though not impossible, event from happening. Signed-off-by: Jiri Podivin Change-Id: I2a1cfe09d850af5c0ebd8cb9ac139d58790f5881 --- tripleo_ipa/roles/tripleo_ipa_registration/tasks/main.yml | 2 ++ .../roles/tripleo_ipa_registration/tasks/services.yml | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tripleo_ipa/roles/tripleo_ipa_registration/tasks/main.yml b/tripleo_ipa/roles/tripleo_ipa_registration/tasks/main.yml index 12d02ab..9289e2d 100644 --- a/tripleo_ipa/roles/tripleo_ipa_registration/tasks/main.yml +++ b/tripleo_ipa/roles/tripleo_ipa_registration/tasks/main.yml @@ -64,3 +64,5 @@ - name: add required services include: services.yml loop: "{{ tripleo_ipa_server_metadata | from_json | parse_service_metadata(base_server_fqdn) }}" + loop_control: + loop_var: required_service diff --git a/tripleo_ipa/roles/tripleo_ipa_registration/tasks/services.yml b/tripleo_ipa/roles/tripleo_ipa_registration/tasks/services.yml index ed36c39..4bade11 100644 --- a/tripleo_ipa/roles/tripleo_ipa_registration/tasks/services.yml +++ b/tripleo_ipa/roles/tripleo_ipa_registration/tasks/services.yml @@ -17,7 +17,7 @@ # The tasks in this file perform the registration process for a service. # # The following variable are required: -# - {item} : which is an ordered tuple of the form: +# - { required_service } : which is an ordered tuple of the form: # -- { sub_host, service } # # An example of this is: @@ -27,8 +27,8 @@ - name: set variables set_fact: - sub_host: "{{ item.0 }}" - service: "{{ item.1 }}" + sub_host: "{{ required_service.0 }}" + service: "{{ required_service.1 }}" - name: add sub_host ipahost: