From the course: Ansible: From Basics to Guru by Pearson

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Lesson 9 lab solution: Working with files

Lesson 9 lab solution: Working with files - Ansible Tutorial

From the course: Ansible: From Basics to Guru by Pearson

Lesson 9 lab solution: Working with files

So we have already been working on this, and this is what we have right now. That's not correct. So how are we going to make this correct? Well, we probably need to check out the hosts.j2 that we generated in the last lesson. And what are we doing? Well, for hosts in groups all, we have hostvars host. And the problem here is that we have the for loop three times. You know what? We don't need it three times. We need it one time. And one time generating lines that contain IP address, FQDN, and hostname. So actually, that shouldn't be too hard. hostVars on host followed by ansible underscore FQDN. And then we also need hostVars, which is the magic variable, by the way. And on the magic variable host, we are going to print the fact. And the fact is Ansible underscore hostname. And then we can end the for loop and remove everything else. And that should be doing it. So how are we going to do it? Well, let's run it again. And there we go. It has just done its work. And we want to check out…

Contents