- name: apply motd
    template: src=motd.j2 dest=/etc/motd

As you can see in this task we have a template file we are going to put into /etc/motd, the file that is being displayed when you log in.

Now, to inform the user about the machine is is logging into we are going to make use of Ansible facts (created by the setup module and when you launch a playbook)

Welcome to {{ ansible_hostname }} ({{ ansible_default_ipv4.address }})
This system is private property.
It is for authorized use only.

This is the motd.j2 file (in the templates folder).
As you can see we are using {{ ansible_hostname }} and ({{ ansible_default_ipv4.address }}.
Those variables (like all the ansible_ ones) are called facts.
You can get them calling Ansible with -m setup and make use of them wherever you like to have a message that is based on some values

Till next time

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s