官术网_书友最值得收藏!

Adding a customized MOTD

To add the MOTD, we will need a template that will be the same for all servers, and a task to use the template.

I find it very useful to add a MOTD to every server. It's even more useful if you use Ansible, because you can use it to warn your users that changes to the system could be overwritten by Ansible. My usual template is called motd, and has this content:

                This system is managed by Ansible 
  Any change done on this system could be overwritten by Ansible 
  
OS: {{ ansible_distribution }} {{ ansible_distribution_version }} 
Hostname: {{ inventory_hostname }} 
eth0 address: {{ ansible_eth0.ipv4.address }} 
 
            All connections are monitored and recorded 
     Disconnect IMMEDIATELY if you are not an authorized user

This is a jinja2 template, and it allows us to use every variable set in the playbooks. This also allows us to use complex syntax for conditionals and cycles that we will see later in this chapter. To populate a file from a template in Ansible, we will need to use the following:

- name: Ensure the MOTD file is present and updated 
  template: 
    src: motd 
    dest: /etc/motd 
    owner: root 
    group: root 
    mode: 0644 
  become: True 

The template module allows us to specify a local file (src) that will be interpreted by jinja2, and the output of this operation will be saved on the remote machine in a specific path (dest), will be owned by a specific user (owner) and group (group), and will have a specific access mode (mode).

主站蜘蛛池模板: 休宁县| 淮滨县| 淳化县| 景东| 内江市| 射洪县| 铜鼓县| 甘南县| 北辰区| 万源市| 东阳市| 保定市| 嘉祥县| 苏尼特右旗| 明水县| 孝感市| 邯郸市| 博爱县| 绥德县| 阳高县| 大邑县| 卓资县| 万年县| 梅河口市| 罗定市| 长岛县| 垫江县| 达州市| 清镇市| 施秉县| 博湖县| 峨山| 陇南市| 三亚市| 普定县| 通渭县| 鄢陵县| 桓台县| 惠东县| 偃师市| 富民县|