红帽RHCE之Ansible-13-J2模板

Ansible-13-J2模板

  • J2模板就是各种配置文件的模板

目录

  • 开始练习
//开始练习
[student@workstation file-manage]$ lab file-template start

Setting up workstation for lab exercise work:

 · The ansible package is installed on workstation.............  SUCCESS
 · Create exercise directory...................................  SUCCESS
 · Download Ansible configuration..............................  SUCCESS
 · Download Ansible inventory..................................  SUCCESS
 · Downloading motd.j2.........................................  SUCCESS
 · Downloading motd.yml........................................  SUCCESS

[student@workstation file-template]$ ls
ansible.cfg  files
[student@workstation file-template]$ cat ansible.cfg 
[defaults]
inventory = inventory
ansible_managed = Ansible managed: modified on %Y-%m-%d %H:%M:%S
[student@workstation file-template]$ tree files/
files/
├── inventory
├── motd.j2
└── motd.yml

0 directories, 3 files
[student@workstation file-template]$ cat files/inventory 
[webservers]
servera.lab.example.com

[workstations]
workstation.lab.example.com
[student@workstation file-template]$ cat files/motd.j2
This is the system {{ ansible_facts['fqdn'] }}.
This is a {{ ansible_facts['distribution'] }} version {{ ansible_facts['distribution_version'] }} system.
Only use this system with permission.
Please report issues to: {{ system_owner }}.
[student@workstation file-template]$ cat files/motd.yml 
---
- name: configure SOE
  hosts: all
  remote_user: devops
  become: true
  vars:
    - system_owner: clyde@example.com
  tasks:
    - name: configure /etc/motd
      template:
        src: motd.j2
        dest: /etc/motd
        owner: root
        group: root
        mode: 0644

//执行前
[kiosk@foundation0 ~]$ ssh servera
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sun Nov 15 22:58:51 2020 from 172.25.250.250
//结果
[kiosk@foundation0 ~]$ ssh servera
Warning: Permanently added 'servera,172.25.250.10' (ECDSA) to the list of known hosts.
This is the system servera.lab.example.com.
This is a RedHat version 8.0 system.
Only use this system with permission.
Please report issues to: clyde@example.com.
Activate the web console with: systemctl enable --now cockpit.socket
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值