Ansible Advanced Template Loops Tutorial - Use Loop Vars in Your Templates

preview_player
Показать описание


"How do I replace vars in the template that change with each loop? For example, what if I want to copy a template for a .gitconfig file for multiple users to each user's home directory?"

Great question! In this tutorial I show you my solution to this problem using the Ansible Template Module with a loop.

- 0:46 -- Playbook & Variables (how I set everything up)
- 1:30 -- Ensure Users Exist
- 3:18 -- Create .gitconfig for Each User (using the loop vars in the template)

Thanks for watching and hope it's entertaining/useful for you! Hit me up in the comments if you have any questions or feedback 💪.

Related & Channel

Our Site & Socials
Рекомендации по теме
Комментарии
Автор

This was exactly i'm looking for - Thx for the great explanation

NebucadLaVey
Автор

Really like you tutorials about ansible modules. Why not keep going? I am looking forward to that.

jhred
Автор

Very good. There are many videos out there where you partly fall asleep. Your series is to the point, interesting and explains things using expertise.

heavenAndHell
Автор

your video is very useful, i watch it to solve the problem that I used to spend a lot of time researching. thank you so

hungdiep
Автор

nice and to the point tutorials. I just started with ansible and I was looking for something exactly like this. Thanks for the great work :)

RAJATRAWAT
Автор

Thanks-I would like to see some tutorial on ansible Role.

hamidhamidi
Автор

Fantastic video series, thank you for sharing! One question for you: I notice you are using a Mac for your environment, but could you share what you are using for your IDE? I have not yet found the perfect IDE for use with Ansible - Being on PC, I typically use Notepad++...

queenannsrevenge
Автор

Super series, well explained and concise.

nardu
Автор

Percy thank you so much for the great content, it helped me a lot.

Sorry for my bad English, not my mother tongue.

patriciomartins
Автор

@Percy Grunwald from TopTechSkills, your explanation is very clear. i have different set of values to be updated in conf file using templates. example <path, match, index> for tomcat log, <path, match, index> for access log. values are getting overidden in the same conf file. how can i append using the same concept you have explained? Can i use 'blockinfile' along with templates?

udaymailforu
Автор

Excellent explaining ....let me know which code writer you are using.

KiranKumar-fokr
Автор

Thank you for the video, I have a question:
If the var list in the video is very long (too many users), can I use jinja template to generate this list and attach this template (without generating a file) to the "vars" section? How can I do that ? Thank you

tamle
Автор

Thanks for the video. Can you also make a video on the uri module?

samratmitra
Автор

Can you please make a video on how to read a csv file data and use the data as a variable to perform certain tasks in loop using ansible

matishbhuyan
Автор

Excellent video. It was amazing. please let us know what is the tool you are using for running and executing the commands.

chandu
Автор

Hi Percy
I really like your videos very clear and helpful
I have a question that I could not find how to do it - I need to create a dictionary during the playbook run

I need to do a nested loop but this is not working ( i know that there is some keyword called nested_item and also with_subelemental )

I need do have that kind of output

dict:
{
server1: {
server1_int: value
},
server2:{
server2_int: value
}
}


the server name should be a jinja2 parameter.

many thanks :)

avishayhakim
Автор

Hey, is there a way to achieve round-robin strategy with ansible while deploying different versions of same app to different servers. Lets say
Version 1 deployed to Server 1, Version 2 deployed to Server 2, Version 3 deployed to Server 3 and then Version 4 will be deployed to Server 1 again and the cycle Thanks

chikkusingh
Автор

How do you handle checking if a file exists for multiple users and then create your .gitconfig?

sampathganji
Автор

Bulls Eye .. Very Very to the point ... How to incorporate read_csv module as source of the list/dict variables into a similar loop ?

muhsintawafig
Автор

Is there a way to use conditional commands like if else inside of template ?

shubhampande