Ansible users have written modules for managing filesystem ACLs, managing Windows Firewall, and managing hostname and domain membership, and more. And when you need to roll this out across your team, Red Hat ® Ansible ® Tower works out of the box with Ansible’s Windows support.
Active8 months ago
Is there an easy way to deploy a folder full of template .j2 folder to a linux box, using the same name as the template, but without the .j2 extension, rather than using the template module for each file?
Right now i have a long list of:
dawud13.7k33 gold badges3333 silver badges5656 bronze badges
Ansible Copy Example
TrolololololTrololololol
6 Answers
You could use
with_fileglob
to get the list of files from your template directory and use filters to strip the j2 extension like this.RussellRussell
Michael DeHaan(creator of Ansible) made a post on CoderWall that talks about very similar issue. You can adjust and expand it according to your needs(such as permissions and ownership).Relevant part of the post is here:
This can be simplified by using '
with_items
' and a single notify
statement. If any of the tasks change, the service will be notified in exactly the same way that it needs to restart at the end of the playbook run.Note that since we have tasks that take more than one unique argument, we don't just say '
item
' in the 'template:
' line, but use with_items
with a hash (dictionary) variable. You can also keep it a little shorter by using lists, if you like. This is a stylistic preference:Of course we could also define the list you were walking over in another file, like a '
MxxMxxgroupvars/webservers
' file to define all the variables needed for the webservers
group, or a YAML file loaded from the 'varsfiles
' directive inside the playbook. Look how this can clean up if we do.1,78211 gold badge1919 silver badges4040 bronze badges
The answer by Russel does work but it needs improvement
RicardoNaMusica rates this game: 5/5This game is a remake of the original Ocarina of Time. Another addition is the different locations that the skultulas are placed and now you will have more difficulty to find them. Even if I write the best adjetives trying to just begin to describe this game, I know I would fall short. This game has all the magic of the first Ocarina of Time, with the differences that the dungeons have different aspects to solve riddles, for instance, you will have to use your ocarina even more and the magic that the fairies give you will have to be used more as well. The legend of zelda ocarina of time master quest gc iso.
Firs of all the $ needs to go as it was wrong regex in the regex_replace . Secondly all the files should be in the files directory rather than templates directory
HJ_VORTEXHJ_VORTEX
I wrote a filetree lookup plugin that can help with actions on file trees.
- https://github.com/ansible/ansible/pull/14332 (Ansible v2.x)
- https://github.com/ansible/ansible/pull/14628 (Ansible v1.9.x)
Ansible Windows Template File Manager
You can recurse over files in a file tree and based on file properties perform actions (e.g. template or copy). Since the relative path is returned, you can recreate the filetree on the target system(s) with ease.
It makes for more readable playbooks.
Ansible Template J2
Dag WieersDag Wieers
The below command worked for me to do a recursive lookup for j2 files in templates and move it to the destination. Hope it helps someone looking for recursive copy of templates to destination.
RobinRobin
There is a possibility to grab the list of actual files from the directory automatically and iterate them afterwards.
Roman DolejsiRoman Dolejsi