//开始练习
[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
Ansible-13-J2模板J2模板就是各种配置文件的模板目录开始练习//开始练习[student@workstation file-manage]$ lab file-template startSetting up workstation for lab exercise work: · The ansible package is installed on workstation............. SUCCESS · Create exercise direct