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

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).

主站蜘蛛池模板: 南汇区| 和平县| 兴安盟| 祁门县| 宜兴市| 澜沧| 琼结县| 龙门县| 桦川县| 榆林市| 婺源县| 钟祥市| 勃利县| 孟州市| 内丘县| 滨州市| 肥乡县| 武汉市| 丰台区| 舟山市| 临颍县| 曲麻莱县| 桐梓县| 榆社县| 平果县| 元江| 武安市| 池州市| 梨树县| 安吉县| 措勤县| 宝坻区| 盘锦市| 祁门县| 巴里| 什邡市| 鸡泽县| 玉田县| 石林| 开平市| 京山县|