From the course: Complete Guide to Configuration Management Using Ansible

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Lesson 8 lab solution: Working with files

Lesson 8 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 host 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 [host], followed by ['ansible_fqdn']. And then we also need hostvars, which is the metric variable, by the way. And on the metric variable host, we are going to print the fact, and the fact is ansible_hostname. And then we can enter 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