[student@workstation ~]$ ssh workstation
//开始练习
[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是ansible配置文件指定Inventory默认的文件,
//如果使用ansible命令不加-i参数,默认就会使用这个Inventory文件。
[student@workstation ~]$ sudo vim /etc/ansible/hosts
[student@workstation ~]$ cat /etc/ansible/hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
# Ex 1: Ungrouped hosts, specify before any group headers.
## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10
# Ex 2: A collection of hosts belonging to the 'webservers' group
## [webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110
# If you have multiple hosts following a pattern you can specify
# them like this:
## www[001:006].example.com
# Ex 3: A collection of database servers in the 'dbservers' group
## [dbservers]
##
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57
# Here's another example of host ranges, this time there are no
# leading 0s:
## db-[99:101]-node.example.com
servera.lab.example.com
[webservers]
serverb.lab.example.com
//检查主机
[student@workstation ~]$ ansible all --list-hosts
hosts (2):
servera.lab.example.com
serverb.lab.example.com
[student@workstation ~]$ ansible ungrouped --list-hosts
hosts (1):
servera.lab.example.com
[student@workstation ~]$ ansible webservers --list-hosts
hosts (1):
serverb.lab.example.com
[student@workstation deploy-inventory]$ vim inventory
[student@workstation deploy-inventory]$ cat inventory
[development]
servera.lab.example.com
[testing]
serverb.lab.example.com
[production]
server[c:d].lab.example.com
[raleigh]
server[a:b].lab.example.com
[mountainview]
serverc.lab.example.com
[london]
serverd.lab.example.com
[webserver]
server[a:d].lab.example.com
[us:children]
raleigh
mountainview
[student@workstation deploy-inventory]$ ansible -i inventory all --list-hosts
hosts (4):
servera.lab.example.com
serverb.lab.example.com
serverc.lab.example.com
serverd.lab.example.com
[student@workstation deploy-inventory]$ ansible -i inventory ungrouped --list-hosts
[WARNING]: No hosts matched, nothing to do
hosts (0):
//完成练习
[student@workstation ~]$ lab deploy-inventory finish
Cleanup workstation control node
· Restore /etc/ansible/hosts.................................. SUCCESS