1、综合实验01
1.1 实验要求
- 开启实验环境
- 安装ansible
- 进入review-deploy目录
- 创建invenory文件,dev组下有servera和serverb两个host
- 创建ansible.cfg文件,指定inventory存放位置
- 通过ad hoc,使用copy模块将字符串Managed by Ansible\n.复制到/etc/motd,并使用devops用户
- 通过ad hoc,使用command模块查看受管节点/etc/motd内容
- 判断成绩,实验结束
1.2 实验
[student@workstation ~]$ lab review-deploy start
Setting up workstation for the review-deploy lab:
. Checking if workstation is reachable........................ SUCCESS
. Checking if servera.lab.example.com is reachable............ SUCCESS
. Checking if serverb.lab.example.com is reachable............ SUCCESS
· Configuring control node packages........................... SUCCESS
· Creating working directory.................................. SUCCESS
# 安装ansible
[student@workstation ~]$ sudo yum install ansible
[sudo] password for student:
Last metadata expiration check: 0:15:46 ago on Sun 18 Sep 2022 09:28:06 PM CST.
Dependencies resolved.
========================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================
Installing:
ansible noarch 2.8.0-1.el8ae rhel-8-server-ansible-2.8-rpms 15 M
Installing dependencies:
sshpass x86_64 1.06-3.el8ae rhel-8-server-ansible-2.8-rpms 27 k
Transaction Summary
========================================================================================================================================================
Install 2 Packages
Total download size: 15 M
Installed size: 78 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): sshpass-1.06-3.el8ae.x86_64.rpm 833 kB/s | 27 kB 00:00
(2/2): ansible-2.8.0-1.el8ae.noarch.rpm 26 MB/s | 15 MB 00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------
Total 26 MB/s | 15 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : sshpass-1.06-3.el8ae.x86_64 1/2
Installing : ansible-2.8.0-1.el8ae.noarch 2/2
Running scriptlet: ansible-2.8.0-1.el8ae.noarch 2/2
Verifying : ansible-2.8.0-1.el8ae.noarch 1/2
Verifying : sshpass-1.06-3.el8ae.x86_64 2/2
Installed:
ansible-2.8.0-1.el8ae.noarch sshpass-1.06-3.el8ae.x86_64
Complete!
[student@workstation review-deploy]$ cat inventory
[dev]
servera.lab.example.com
serverb.lab.example.com
[student@workstation review-deploy]$ cat ansible.cfg
[defaults]
inventory = ./inventory
ansible dev -m copy -a 'content="Managed by Ansible\n" dest="/etc/motd"' -u devops -b
[student@workstation review-deploy]$ ansible dev -m copy -a 'content="Managed by Ansible\n" dest="/etc/motd"' -u devops -b
serverb.lab.example.com | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"checksum": "4458b979ede3c332f8f2128385df4ba305e58c27",
"dest": "/etc/motd",
"gid": 0,
"group": "root",
"md5sum": "65a4290ee5559756ad04e558b0e0c4e3",
"mode": "0644",
"owner": "root",
"secontext": "system_u:object_r:etc_t:s0",
"size": 19,
"src": "/home/devops/.ansible/tmp/ansible-tmp-1663510230.0597143-90062928491478/source",
"state": "file",
"uid": 0
}
servera.lab.example.com | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"checksum": "4458b979ede3c332f8f2128385df4ba305e58c27",
"dest": "/etc/motd",
"gid": 0,
"group": "root",
"md5sum": "65a4290ee5559756ad04e558b0e0c4e3",
"mode": "0644",
"owner": "root",
"secontext": "unconfined_u:object_r:etc_t:s0",
"size": 19,
"src": "/home/devops/.ansible/tmp/ansible-tmp-1663510230.0465944-50399335671769/source",
"state": "file",
"uid": 0
}
[student@workstation review-deploy]$ ansible dev -m command -a 'cat /etc/motd'
serverb.lab.example.com | CHANGED | rc=0 >>
Managed by Ansible
servera.lab.example.com | CHANGED | rc=0 >>
Managed by Ansible
ansible dev -m command -a 'cat /etc/motd'
[student@workstation review-deploy]$ lab review-deploy grade
Grading the student's work on workstation:
. Checking if Ansible is installed............................ PASS
. Checking inventory file exists.............................. PASS
. Checking the host groups defined............................ PASS
. Verifying the /etc/motd file content........................ PASS
Overall lab grade.............................................. PASS
[student@workstation review-deploy]$ lab review-deploy finish
Cleaning up for the (review-deploy) lab:
. Undoing ad hoc tasks........................................ SUCCESS