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

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

主站蜘蛛池模板: 吴川市| 安平县| 卢湾区| 苗栗县| 贵阳市| 太康县| 克什克腾旗| 彭泽县| 体育| 东兰县| 郎溪县| 那曲县| 郯城县| 台南市| 高密市| 太保市| 杭州市| 彝良县| 芜湖市| 鹿邑县| 永靖县| 晋城| 安仁县| 阜新| 深州市| 阿拉善右旗| 百色市| 千阳县| 安溪县| 茌平县| 仙桃市| 新丰县| 沐川县| 从江县| 通江县| 惠东县| 崇州市| 宜章县| 永定县| 常山县| 文水县|