Playing with Ansible I did get the idea to make a
nice welcome message when you log in to a server. This message needs to
be placed in a file, which is configured in /etc/ssh/sshd_config
with
the banner
option. I call this file /etc/issue
.
Of course I want to deploy this file with Ansible, so I first defined
an entry in the hosts
file. This looks like this:
# Settings for master [master] master # Variables for master [master:vars] location=cow shed room=ESX5i issueremarks=This is the master Ansible server. Please be carefull!!
and this is parsed through a Jinja2 template which looks like
{{ figlethost.stdout }}
------------------------------------------------------------------------------
-- W A R N I N G --
UNAUTHORIZED ACCESS STRICTLY PROHIBITED!!
------------------------------------------------------------------------------
System Name : {{ "%-25s"|format(ansible_hostname) }} Location : {{ location }}
Managed by : {{ "%-25s"|format(name) }} Room : {{ room }}
------------------------------------------------------------------------------
{% if issueremarks is defined %}
{{ issueremarks.center(80) }}
------------------------------------------------------------------------------
{% endif %}
When combining this all into a playbook this results in
---
- hosts: all
tasks:
- name: install figlet
yum: pkg=figlet state=latest
- name: figlet name
command: /usr/bin/figlet -c -w 80 ${ansible_hostname}
register: figlethost
- name: deploy issue file
template: src=issue.in dest=/etc/issue owner=root mode=0444
As you can see there is a registered variable, called figlethost
which
contains the hostname parsed through figlet
.
And putting it all together this gives
_ _ __ ___ __ _ ___| |_ ___ _ __ | '_ ` _ \ / _` / __| __/ _ \ '__| | | | | | | (_| \__ \ || __/ | |_| |_| |_|\__,_|___/\__\___|_| ------------------------------------------------------------------------------ -- W A R N I N G -- UNAUTHORIZED ACCESS STRICTLY PROHIBITED!! ------------------------------------------------------------------------------ System Name : master Location : cow shed Managed by : Ton Kersten Room : ESX5i ------------------------------------------------------------------------------ This is the master Ansible server. Please be carefull!! ------------------------------------------------------------------------------