Ansible Tips and Tricks ( Part 2 )

Courtesy: revelwood.com

Trick 2: Ansible Loop Inside another Loop

Task 1: copy template x
Task 2: copy template y
Task 3: copy template z
.....
Task 1: copy template x ( task1.yml )
Task 2: copy template y ( task2.yml )
Task 3: copy template z ( task3.yml )
.....
Main File:Run Dynamic Task: copy template
parameter list:
template x
template y
.....
Dynamic Task:
Actual Copy of Template
---
- name: Creating kafka configurations | {{ kafkaConfigFile }}
template:
src: "{{ kafkaConfigFile }}"
dest: "{{ kafkaInstallDir }}/kafka_{{ kafkaScalaVersion }}-{{ kafkaVersion }}/config/{{ kafkaConfigFile }}"
register: configStatus
- name: Creating kafka configurations
include_role:
name: configure
tasks_from: dynamicConfigs.yml
vars:
- kafkaConfigFile: "{{ item }}"
loop:
- kafka-broker.properties
- log4j.properties
- hosts: clusterNodes:clusterAddNodes
gather_facts: true
serial: 1
tasks:
- include_role:
name: configure
tasks_from: dynamicConfigs
vars:
- kafkaConfigFile: kafka-broker.properties

--

--

Principal Software Architect I ( R&D DevOps )

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store