构建ansible清单

以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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值