From f8fdc0cd939de0e46cd968c6afb0fe91b72f78d0 Mon Sep 17 00:00:00 2001
From: andreyshestakov <ashestakov@mirantis.com>
Date: Tue, 23 Apr 2019 09:34:10 +0300
Subject: [PATCH] Optimize kube resources creation (#4572)

---
 contrib/metallb/roles/provision/tasks/main.yml        |  4 +---
 .../roles/kubernetes-pv/ansible/tasks/main.yaml       |  5 +----
 roles/kubernetes-apps/ansible/tasks/dashboard.yml     |  5 +----
 roles/kubernetes-apps/ansible/tasks/main.yml          | 11 +----------
 roles/kubernetes-apps/ansible/tasks/netchecker.yml    |  7 ++-----
 roles/kubernetes-apps/cluster_roles/tasks/main.yml    |  9 ++-------
 .../nvidia_gpu/tasks/main.yml                         |  6 +-----
 .../cephfs_provisioner/tasks/main.yml                 |  5 +----
 .../local_path_provisioner/tasks/main.yml             |  5 +----
 .../local_volume_provisioner/tasks/main.yml           |  7 +------
 roles/kubernetes-apps/helm/tasks/main.yml             |  5 +----
 .../ingress_controller/cert_manager/tasks/main.yml    |  8 ++------
 .../ingress_controller/ingress_nginx/tasks/main.yml   |  5 +----
 roles/kubernetes-apps/metrics_server/tasks/main.yml   |  5 +----
 .../network_plugin/calico/tasks/main.yml              | 10 ++--------
 .../network_plugin/canal/tasks/main.yml               |  7 ++-----
 .../network_plugin/cilium/tasks/main.yml              |  7 ++-----
 .../network_plugin/contiv/tasks/main.yml              |  5 +----
 .../network_plugin/flannel/tasks/main.yml             |  7 ++-----
 .../network_plugin/multus/tasks/main.yml              |  7 ++-----
 .../policy_controller/calico/tasks/main.yml           |  9 +--------
 roles/kubernetes-apps/registry/tasks/main.yml         | 10 ++--------
 22 files changed, 31 insertions(+), 118 deletions(-)

diff --git a/contrib/metallb/roles/provision/tasks/main.yml b/contrib/metallb/roles/provision/tasks/main.yml
index 6b9661de4..2bc5f9efe 100644
--- a/contrib/metallb/roles/provision/tasks/main.yml
+++ b/contrib/metallb/roles/provision/tasks/main.yml
@@ -8,11 +8,9 @@
     - "inventory_hostname == groups['kube-master'][0]"
 - name: "Kubernetes Apps | Install and configure MetalLB"
   kube:
-    name: "MetalLB"
     kubectl: "{{bin_dir}}/kubectl"
-    filename: "{{ kube_config_dir }}/{{ item.item }}"
+    filename: "{{ rendering.results | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "{{ item.changed | ternary('latest','present') }}"
   become: true
-  with_items: "{{ rendering.results }}"
   when:
     - "inventory_hostname == groups['kube-master'][0]"
diff --git a/contrib/network-storage/glusterfs/roles/kubernetes-pv/ansible/tasks/main.yaml b/contrib/network-storage/glusterfs/roles/kubernetes-pv/ansible/tasks/main.yaml
index 2e108701a..001007f49 100644
--- a/contrib/network-storage/glusterfs/roles/kubernetes-pv/ansible/tasks/main.yaml
+++ b/contrib/network-storage/glusterfs/roles/kubernetes-pv/ansible/tasks/main.yaml
@@ -10,11 +10,8 @@
 
 - name: Kubernetes Apps | Set GlusterFS endpoint and PV
   kube:
-    name: glusterfs
     namespace: default
     kubectl: "{{bin_dir}}/kubectl"
-    resource: "{{item.item.type}}"
-    filename: "{{kube_config_dir}}/{{item.item.dest}}"
+    filename: "{{ gluster_pv.results | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "{{item.changed | ternary('latest','present') }}"
-  with_items: "{{ gluster_pv.results }}"
   when: inventory_hostname == groups['kube-master'][0] and groups['gfs-cluster'] is defined
diff --git a/roles/kubernetes-apps/ansible/tasks/dashboard.yml b/roles/kubernetes-apps/ansible/tasks/dashboard.yml
index 4c9ad5c74..6f2c7e11f 100644
--- a/roles/kubernetes-apps/ansible/tasks/dashboard.yml
+++ b/roles/kubernetes-apps/ansible/tasks/dashboard.yml
@@ -21,11 +21,8 @@
 
 - name: Kubernetes Apps | Start dashboard
   kube:
-    name: "{{ item.item.name }}"
     namespace: "kube-system"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/{{ item.item.file }}"
+    filename: "{{ manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
-  with_items: "{{ manifests.results }}"
   when: inventory_hostname == groups['kube-master'][0]
diff --git a/roles/kubernetes-apps/ansible/tasks/main.yml b/roles/kubernetes-apps/ansible/tasks/main.yml
index 166b4ec4c..196afc23c 100644
--- a/roles/kubernetes-apps/ansible/tasks/main.yml
+++ b/roles/kubernetes-apps/ansible/tasks/main.yml
@@ -38,20 +38,13 @@
 
 - name: Kubernetes Apps | Start Resources
   kube:
-    name: "{{ item.item.name }}"
     namespace: "kube-system"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/{{ item.item.file }}"
+    filename: "{{ (coredns_manifests.results|default([]) + coredns_secondary_manifests.results|default([]) + nodelocaldns_manifests.results|default([])) | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
-  with_items:
-    - "{{ coredns_manifests.results | default({}) }}"
-    - "{{ coredns_secondary_manifests.results | default({}) }}"
-    - "{{ nodelocaldns_manifests.results | default({}) }}"
   when:
     - dns_mode != 'none'
     - inventory_hostname == groups['kube-master'][0]
-    - not item is skipped
   register: resource_result
   until: resource_result is succeeded
   retries: 4
@@ -59,8 +52,6 @@
   tags:
     - coredns
     - nodelocaldns
-  loop_control:
-    label: "{{ item.item.file }}"
 
 - name: Kubernetes Apps | Netchecker
   import_tasks: tasks/netchecker.yml
diff --git a/roles/kubernetes-apps/ansible/tasks/netchecker.yml b/roles/kubernetes-apps/ansible/tasks/netchecker.yml
index 01720eaf7..c8d9c39de 100644
--- a/roles/kubernetes-apps/ansible/tasks/netchecker.yml
+++ b/roles/kubernetes-apps/ansible/tasks/netchecker.yml
@@ -62,11 +62,8 @@
 
 - name: Kubernetes Apps | Start Netchecker Resources
   kube:
-    name: "{{item.item.name}}"
     namespace: "{{netcheck_namespace}}"
     kubectl: "{{bin_dir}}/kubectl"
-    resource: "{{item.item.type}}"
-    filename: "{{kube_config_dir}}/{{item.item.file}}"
+    filename: "{{ manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
-  with_items: "{{ manifests.results }}"
-  when: inventory_hostname == groups['kube-master'][0] and not item is skipped
+  when: inventory_hostname == groups['kube-master'][0]
diff --git a/roles/kubernetes-apps/cluster_roles/tasks/main.yml b/roles/kubernetes-apps/cluster_roles/tasks/main.yml
index f58dda1bb..e7acb57a6 100644
--- a/roles/kubernetes-apps/cluster_roles/tasks/main.yml
+++ b/roles/kubernetes-apps/cluster_roles/tasks/main.yml
@@ -41,21 +41,16 @@
 
 - name: Kubernetes Apps | Add policies, roles, bindings for PodSecurityPolicy
   kube:
-    name: "{{item.item.name}}"
     kubectl: "{{bin_dir}}/kubectl"
-    resource: "{{item.item.type}}"
-    filename: "{{kube_config_dir}}/{{item.item.file}}"
+    filename: "{{ psp_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
   register: result
   until: result is succeeded
   retries: 10
   delay: 6
-  with_items: "{{ psp_manifests.results }}"
   when:
+    - podsecuritypolicy_enabled
     - inventory_hostname == groups['kube-master'][0]
-    - not item is skipped
-  loop_control:
-    label: "{{ item.item.file }}"
 
 - name: Kubernetes Apps | Add ClusterRoleBinding to admit nodes
   template:
diff --git a/roles/kubernetes-apps/container_engine_accelerator/nvidia_gpu/tasks/main.yml b/roles/kubernetes-apps/container_engine_accelerator/nvidia_gpu/tasks/main.yml
index 50822be7d..dbd93e727 100644
--- a/roles/kubernetes-apps/container_engine_accelerator/nvidia_gpu/tasks/main.yml
+++ b/roles/kubernetes-apps/container_engine_accelerator/nvidia_gpu/tasks/main.yml
@@ -42,13 +42,9 @@
 
 - name: Container Engine Acceleration Nvidia GPU | Apply manifests for nvidia accelerators
   kube:
-    name: "{{ item.item.name }}"
     namespace: "kube-system"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/addons/container_engine_accelerator/{{ item.item.file }}"
+    filename: "{{ container_engine_accelerator_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/addons/container_engine_accelerator/\\1') | list }}"
     state: "latest"
-  with_items:
-    - "{{container_engine_accelerator_manifests.results}}"
   when:
     - inventory_hostname == groups['kube-master'][0] and nvidia_driver_install_container and nvidia_driver_install_supported
diff --git a/roles/kubernetes-apps/external_provisioner/cephfs_provisioner/tasks/main.yml b/roles/kubernetes-apps/external_provisioner/cephfs_provisioner/tasks/main.yml
index c93ecfde7..4dc9be610 100644
--- a/roles/kubernetes-apps/external_provisioner/cephfs_provisioner/tasks/main.yml
+++ b/roles/kubernetes-apps/external_provisioner/cephfs_provisioner/tasks/main.yml
@@ -69,11 +69,8 @@
 
 - name: CephFS Provisioner | Apply manifests
   kube:
-    name: "{{ item.item.name }}"
     namespace: "{{ cephfs_provisioner_namespace }}"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/addons/cephfs_provisioner/{{ item.item.file }}"
+    filename: "{{ cephfs_provisioner_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/addons/cephfs_provisioner/\\1') | list }}"
     state: "latest"
-  with_items: "{{ cephfs_provisioner_manifests.results }}"
   when: inventory_hostname == groups['kube-master'][0]
diff --git a/roles/kubernetes-apps/external_provisioner/local_path_provisioner/tasks/main.yml b/roles/kubernetes-apps/external_provisioner/local_path_provisioner/tasks/main.yml
index 27d52ad7c..1d7ece7f1 100644
--- a/roles/kubernetes-apps/external_provisioner/local_path_provisioner/tasks/main.yml
+++ b/roles/kubernetes-apps/external_provisioner/local_path_provisioner/tasks/main.yml
@@ -30,11 +30,8 @@
 
 - name: Local Path Provisioner | Apply manifests
   kube:
-    name: "{{ item.item.name }}"
     namespace: "{{ local_path_provisioner_namespace }}"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/addons/local_path_provisioner/{{ item.item.file }}"
+    filename: "{{ local_path_provisioner_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/addons/local_path_provisioner/\\1') | list }}"
     state: "latest"
-  with_items: "{{ local_path_provisioner_manifests.results }}"
   when: inventory_hostname == groups['kube-master'][0]
diff --git a/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/tasks/main.yml b/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/tasks/main.yml
index 6b970317e..d5a087605 100644
--- a/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/tasks/main.yml
+++ b/roles/kubernetes-apps/external_provisioner/local_volume_provisioner/tasks/main.yml
@@ -50,13 +50,8 @@
 
 - name: Local Volume Provisioner | Apply manifests
   kube:
-    name: "{{ item.item.name }}"
     namespace: "{{ local_volume_provisioner_namespace }}"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/addons/local_volume_provisioner/{{ item.item.file }}"
+    filename: "{{ local_volume_provisioner_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/addons/local_volume_provisioner/\\1') | list }}"
     state: "latest"
-  with_items: "{{ local_volume_provisioner_manifests.results }}"
   when: inventory_hostname == groups['kube-master'][0]
-  loop_control:
-    label: "{{ item.item.file }}"
diff --git a/roles/kubernetes-apps/helm/tasks/main.yml b/roles/kubernetes-apps/helm/tasks/main.yml
index c8dfd81ba..0cb676d43 100644
--- a/roles/kubernetes-apps/helm/tasks/main.yml
+++ b/roles/kubernetes-apps/helm/tasks/main.yml
@@ -20,13 +20,10 @@
 
 - name: Helm | Apply Helm Manifests (RBAC)
   kube:
-    name: "{{item.item.name}}"
     namespace: "{{ tiller_namespace }}"
     kubectl: "{{bin_dir}}/kubectl"
-    resource: "{{item.item.type}}"
-    filename: "{{kube_config_dir}}/{{item.item.file}}"
+    filename: "{{ manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
-  with_items: "{{ manifests.results }}"
   when:
     - dns_mode != 'none'
     - inventory_hostname == groups['kube-master'][0]
diff --git a/roles/kubernetes-apps/ingress_controller/cert_manager/tasks/main.yml b/roles/kubernetes-apps/ingress_controller/cert_manager/tasks/main.yml
index d8ca7ad17..d8ceb206e 100644
--- a/roles/kubernetes-apps/ingress_controller/cert_manager/tasks/main.yml
+++ b/roles/kubernetes-apps/ingress_controller/cert_manager/tasks/main.yml
@@ -47,12 +47,8 @@
 
 - name: Cert Manager | Apply manifests
   kube:
-    name: "{{ item.item.name }}"
     namespace: "{{ cert_manager_namespace }}"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/addons/cert_manager/{{ item.item.file }}"
+    filename: "{{ cert_manager_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/addons/cert_manager/\\1') | list }}"
     state: "latest"
-  with_items: "{{ cert_manager_manifests.results }}"
-  when:
-    - inventory_hostname == groups['kube-master'][0]
+  when: inventory_hostname == groups['kube-master'][0]
diff --git a/roles/kubernetes-apps/ingress_controller/ingress_nginx/tasks/main.yml b/roles/kubernetes-apps/ingress_controller/ingress_nginx/tasks/main.yml
index c3c5d9c17..e4f55caff 100644
--- a/roles/kubernetes-apps/ingress_controller/ingress_nginx/tasks/main.yml
+++ b/roles/kubernetes-apps/ingress_controller/ingress_nginx/tasks/main.yml
@@ -61,12 +61,9 @@
 
 - name: NGINX Ingress Controller | Apply manifests
   kube:
-    name: "{{ item.item.name }}"
     namespace: "{{ ingress_nginx_namespace }}"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/addons/ingress_nginx/{{ item.item.file }}"
+    filename: "{{ ingress_nginx_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/addons/ingress_nginx/\\1') | list }}"
     state: "latest"
-  with_items: "{{ ingress_nginx_manifests.results }}"
   when:
     - inventory_hostname == groups['kube-master'][0]
diff --git a/roles/kubernetes-apps/metrics_server/tasks/main.yml b/roles/kubernetes-apps/metrics_server/tasks/main.yml
index d7dc45443..2e6ee7ffc 100644
--- a/roles/kubernetes-apps/metrics_server/tasks/main.yml
+++ b/roles/kubernetes-apps/metrics_server/tasks/main.yml
@@ -47,11 +47,8 @@
 
 - name: Metrics Server | Apply manifests
   kube:
-    name: "{{ item.item.name }}"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/addons/metrics_server/{{ item.item.file }}"
+    filename: "{{ metrics_server_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/addons/metrics_server/\\1') | list }}"
     state: "latest"
-  with_items: "{{ metrics_server_manifests.results }}"
   when:
     - inventory_hostname == groups['kube-master'][0]
diff --git a/roles/kubernetes-apps/network_plugin/calico/tasks/main.yml b/roles/kubernetes-apps/network_plugin/calico/tasks/main.yml
index 1be16776f..a88098605 100644
--- a/roles/kubernetes-apps/network_plugin/calico/tasks/main.yml
+++ b/roles/kubernetes-apps/network_plugin/calico/tasks/main.yml
@@ -1,18 +1,12 @@
 ---
 - name: Start Calico resources
   kube:
-    name: "{{item.item.name}}"
     namespace: "kube-system"
     kubectl: "{{bin_dir}}/kubectl"
-    resource: "{{item.item.type}}"
-    filename: "{{kube_config_dir}}/{{item.item.file}}"
+    filename: "{{ calico_node_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
-  with_items:
-    - "{{ calico_node_manifests.results }}"
   when:
-    - inventory_hostname == groups['kube-master'][0] and not item is skipped
-  loop_control:
-    label: "{{ item.item.file }}"
+    - inventory_hostname == groups['kube-master'][0]
 
 - name: "calico upgrade complete"
   shell: "{{ bin_dir }}/calico-upgrade complete --no-prompts --apiconfigv1 /etc/calico/etcdv2.yml --apiconfigv3 /etc/calico/etcdv3.yml"
diff --git a/roles/kubernetes-apps/network_plugin/canal/tasks/main.yml b/roles/kubernetes-apps/network_plugin/canal/tasks/main.yml
index d5776def1..3c27e9547 100644
--- a/roles/kubernetes-apps/network_plugin/canal/tasks/main.yml
+++ b/roles/kubernetes-apps/network_plugin/canal/tasks/main.yml
@@ -1,11 +1,8 @@
 ---
 - name: Canal | Start Resources
   kube:
-    name: "{{item.item.name}}"
     namespace: "kube-system"
     kubectl: "{{bin_dir}}/kubectl"
-    resource: "{{item.item.type}}"
-    filename: "{{kube_config_dir}}/{{item.item.file}}"
+    filename: "{{ canal_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
-  with_items: "{{ canal_manifests.results }}"
-  when: inventory_hostname == groups['kube-master'][0] and not item is skipped
+  when: inventory_hostname == groups['kube-master'][0]
diff --git a/roles/kubernetes-apps/network_plugin/cilium/tasks/main.yml b/roles/kubernetes-apps/network_plugin/cilium/tasks/main.yml
index 363f795a4..974a00c7c 100755
--- a/roles/kubernetes-apps/network_plugin/cilium/tasks/main.yml
+++ b/roles/kubernetes-apps/network_plugin/cilium/tasks/main.yml
@@ -1,14 +1,11 @@
 ---
 - name: Cilium | Start Resources
   kube:
-    name: "{{item.item.name}}"
     namespace: "kube-system"
     kubectl: "{{bin_dir}}/kubectl"
-    resource: "{{item.item.type}}"
-    filename: "{{kube_config_dir}}/{{item.item.file}}"
+    filename: "{{ cilium_node_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
-  with_items: "{{ cilium_node_manifests.results }}"
-  when: inventory_hostname == groups['kube-master'][0] and not item is skipped
+  when: inventory_hostname == groups['kube-master'][0]
 
 - name: Cilium | Wait for pods to run
   command: "{{bin_dir}}/kubectl -n kube-system get pods -l k8s-app=cilium -o jsonpath='{.items[?(@.status.containerStatuses[0].ready==false)].metadata.name}'"  # noqa 601
diff --git a/roles/kubernetes-apps/network_plugin/contiv/tasks/main.yml b/roles/kubernetes-apps/network_plugin/contiv/tasks/main.yml
index 1bca92329..b694b2d48 100644
--- a/roles/kubernetes-apps/network_plugin/contiv/tasks/main.yml
+++ b/roles/kubernetes-apps/network_plugin/contiv/tasks/main.yml
@@ -2,13 +2,10 @@
 
 - name: Contiv | Create Kubernetes resources
   kube:
-    name: "{{ item.item.name }}"
     namespace: "kube-system"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ contiv_config_dir }}/{{ item.item.file }}"
+    filename: "{{contiv_manifests_results.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', contiv_config_dir+'/\\1') | list }}"
     state: "{{ item.changed | ternary('latest','present') }}"
-  with_items: "{{ contiv_manifests_results.results }}"
   run_once: true
 
 - import_tasks: configure.yml
diff --git a/roles/kubernetes-apps/network_plugin/flannel/tasks/main.yml b/roles/kubernetes-apps/network_plugin/flannel/tasks/main.yml
index 2be0739f8..17a6745f2 100644
--- a/roles/kubernetes-apps/network_plugin/flannel/tasks/main.yml
+++ b/roles/kubernetes-apps/network_plugin/flannel/tasks/main.yml
@@ -1,14 +1,11 @@
 ---
 - name: Flannel | Start Resources
   kube:
-    name: "{{item.item.name}}"
     namespace: "kube-system"
     kubectl: "{{bin_dir}}/kubectl"
-    resource: "{{item.item.type}}"
-    filename: "{{kube_config_dir}}/{{item.item.file}}"
+    filename: "{{ flannel_node_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
-  with_items: "{{ flannel_node_manifests.results }}"
-  when: inventory_hostname == groups['kube-master'][0] and not item is skipped
+  when: inventory_hostname == groups['kube-master'][0]
 
 - name: Flannel | Wait for flannel subnet.env file presence
   wait_for:
diff --git a/roles/kubernetes-apps/network_plugin/multus/tasks/main.yml b/roles/kubernetes-apps/network_plugin/multus/tasks/main.yml
index 9d7669cc7..f002cca17 100644
--- a/roles/kubernetes-apps/network_plugin/multus/tasks/main.yml
+++ b/roles/kubernetes-apps/network_plugin/multus/tasks/main.yml
@@ -1,11 +1,8 @@
 ---
 - name: Multus | Start resources
   kube:
-    name: "{{item.item.name}}"
     namespace: "kube-system"
     kubectl: "{{bin_dir}}/kubectl"
-    resource: "{{item.item.type}}"
-    filename: "{{kube_config_dir}}/{{item.item.file}}"
+    filename: "{{ (multus_manifest_1.results + multus_manifest_2.results) | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
-  with_items: "{{ multus_manifest_1.results }} + {{multus_manifest_2.results }}"
-  when: inventory_hostname == groups['kube-master'][0] and not item|skipped
+  when: inventory_hostname == groups['kube-master'][0]
diff --git a/roles/kubernetes-apps/policy_controller/calico/tasks/main.yml b/roles/kubernetes-apps/policy_controller/calico/tasks/main.yml
index 3dfbf0a37..b35403ad7 100644
--- a/roles/kubernetes-apps/policy_controller/calico/tasks/main.yml
+++ b/roles/kubernetes-apps/policy_controller/calico/tasks/main.yml
@@ -24,16 +24,9 @@
 
 - name: Start of Calico kube controllers
   kube:
-    name: "{{item.item.name}}"
     namespace: "kube-system"
     kubectl: "{{bin_dir}}/kubectl"
-    resource: "{{item.item.type}}"
-    filename: "{{kube_config_dir}}/{{item.item.file}}"
+    filename: "{{ calico_node_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/\\1') | list }}"
     state: "latest"
-  with_items:
-    - "{{ calico_kube_manifests.results }}"
   when:
     - inventory_hostname == groups['kube-master'][0]
-    - not item is skipped
-  loop_control:
-    label: "{{ item.item.file }}"
\ No newline at end of file
diff --git a/roles/kubernetes-apps/registry/tasks/main.yml b/roles/kubernetes-apps/registry/tasks/main.yml
index 05f8f4703..803fb6a9c 100644
--- a/roles/kubernetes-apps/registry/tasks/main.yml
+++ b/roles/kubernetes-apps/registry/tasks/main.yml
@@ -42,13 +42,10 @@
 
 - name: Registry | Apply manifests
   kube:
-    name: "{{ item.item.name }}"
     namespace: "{{ registry_namespace }}"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/addons/registry/{{ item.item.file }}"
+    filename: "{{ registry_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/addons/registry/\\1') | list }}"
     state: "latest"
-  with_items: "{{ registry_manifests.results }}"
   when: inventory_hostname == groups['kube-master'][0]
 
 - name: Registry | Create PVC manifests
@@ -65,13 +62,10 @@
 
 - name: Registry | Apply PVC manifests
   kube:
-    name: "{{ item.item.name }}"
     namespace: "{{ registry_namespace }}"
     kubectl: "{{ bin_dir }}/kubectl"
-    resource: "{{ item.item.type }}"
-    filename: "{{ kube_config_dir }}/addons/registry/{{ item.item.file }}"
+    filename: "{{ registry_manifests.results | selectattr('skipped', 'undefined') | map(attribute='item') | map(attribute='file') | map('regex_replace', '^(.*)$', kube_config_dir+'/addons/registry/\\1') | list }}"
     state: "latest"
-  with_items: "{{ registry_manifests.results }}"
   when:
     - registry_storage_class != none and registry_storage_class != ""
     - registry_disk_size != none and registry_disk_size != ""
-- 
GitLab