Ansible Template
One way to make changes to files is using templates. Ansibe uses the Jinja2 template format.
In the ansible-workshop/playbooks/templates directory you’ll see a file motd.j2 template file that we’ll use to modify the /etc/motd file on our target systems. The template takes advantage of ansible facts to make changes to the file that are custom to the system by using variables derived from facts.
After reviewing the template file, review the motd.yml playbook. Notice that you set the ownership and permissions for the file. Alls file related modules support these same directives.
After reviewing the file, execute the playbook:
After the playbook completes successfully, logon to one of the systems to verify what happened.
Take a look at the /etc/motd file to view our changes. Be sure to exit when done.