以student 用户身份并使用student作为密码登录workstation.
在workstation 上,运行lab deploy-inventory start 命令。此起始脚本将确保受管主机servera、serverb、serverc、serverd 可在网路上访问.
[student@workstation ~]$ lab deploy-inventory start
Setting up workstation for lab exercise work:
· Verify ansible is installed on workstation control node..... SUCCESS
· Backup /etc/ansible/hosts inventory......................... SUCCESS
修改 /etc/ansible/hosts 以包括servera.lab.example.com 作为受管主机
[student@workstation ~]$ sudo vim /etc/ansible/hosts
末尾添加:
servera.lab.example.com
[webservers]
serverb.lab.example.com
验证/etc/ansible/hosts清单文件中的受管主机
1、列出默认清单文件中的所有受管主机
[student@workstation ~]$ ansible all --list-hosts
hosts (2):
servera.lab.example.com
serverb.lab.example.com
2、仅列出不属于某个组的受管主机
[student@workstation ~]$ ansible ungrouped --list-hosts
hosts (1):
servera.lab.example.com
3、仅列出属于webservers 组的受管主机
[student@workstation ~]$ ansible webservers --list-hosts
hosts (1):
serverb.lab.example.com
在 /home/student/deploy-inventory 工作目录中,创建一个名为inventory的自定义金泰清单文件:
创建/home/student/deploy-inventory工作目录
[student@workstation ~]$ mkdir ~/deploy-inventory
编辑inventory文件斌添加内容
[student@workstation ~]$ cd ~/deploy-inventory
[student@workstation ~]$ vim inventory
添加:
[webservers]
server[a:b].lab.example.com
[raleigh]
servera.lab.example.com
serverb.lab.example.com
[mountainview]
serverc.lab.example.com
[london]
serverd.lab.example.com
[development]
servera.lab.example.com
[testing]
serverb.lab.example.com
[production]
serverc.lab.example.com
serverd.lab.example.com
[us:children]
raleigh
mountainview
使用 ansible host-or-group -i inventory --list-hosts 命令的变体验自定义 /home/student/deploy-inventory/inventory 清单文件中的受管主机和组:
1、列出所有受管主机
[student@workstation deploy-inventory]$ ansible all -i inventory --list-hosts
hosts (4):
servera.lab.example.com
serverb.lab.example.com
serverd.lab.example.com
serverc.lab.example.com
2、列出清单文件中列出的、但不属于某个组的所有受管主机
[student@workstation deploy-inventory]$ ansible ungrouped -i inventory --list-hosts
[WARNING]: No hosts matched, nothing to do
hosts (0):
3、列出development 组中列出的所有受管主机
[student@workstation deploy-inventory]$ ansible development -i inventory --list-hosts
hosts (1):
servera.lab.example.com
4、列出testing组中列出的所有受管主机
[student@workstation deploy-inventory]$ ansible testing -i inventory --list-hosts
hosts (1):
serverb.lab.example.com
5、列出production组中列出的所有受管主机
[student@workstation deploy-inventory]$ ansible production -i inventory --list-hosts
hosts (2):
serverc.lab.example.com
serverd.lab.example.com
6、列出us组中列出的所有受管主机
[student@workstation deploy-inventory]$ ansible us -i inventory --list-hosts
hosts (3):
servera.lab.example.com
serverb.lab.example.com
serverc.lab.example.com
完成:
运行lab intro-install finish脚本来清理本练习
[student@workstation deploy-inventory]$ lab deploy-inventory finish
Cleanup workstation control node
· Restore /etc/ansible/hosts.................................. SUCCESS