管理ansible配置文件

首先以student用户身份并使用student作为密码登录workstation.

在workstation 上,运行lab deploy-manage start 命令。此脚本将确保受管主机 servera 可在网络上访问。
        [student@workstation ~]$ lab deploy-manage start
        Setting up workstation for lab exercise work:

         · ansible package is installed on workstation.................  SUCCESS

创建目录 /home/student/deploy-manage ,拥于包含本练习的文件。更改到这个新建的目录
        [student@workstation ~]$ mkdir ~/deploy-manage
        [student@workstation ~]$ cd ~/deploy-manage

编辑新文件 ansible.vfg
        [student@workstation deploy-manage]$ vim ansible.cfg
        添加:
        [defaults]
        inventory = ./inventory

编辑新的静态清单文件inventory :含 四个主机
        · [myself]应包含主机localhost;
        · [intranetweb]应包含主机servera.lab.example.com;
        · [internetweb]应包含主机serverb.lab.example.com;
        · [web]应包含intranetweb和internetweb主机组。
        [student@workstation deploy-manage]$ vim inventory
        添加:

        [myself]
        localhost

        [intranetweb]
        servera.lab.example.com

        [internetweb]
        serverb.lab.example.com

        [web:children]
        intranetweb
        internetweb

测试主机组配置:
        [student@workstation deploy-manage]$ ansible myself --list-hosts
          hosts (1):
            localhost
        [student@workstation deploy-manage]$ ansible intranetweb --list-hosts
          hosts (1):
            servera.lab.example.com
        [student@workstation deploy-manage]$ ansible internetweb  --list-hosts
          hosts (1):
            serverb.lab.example.com
        [student@workstation deploy-manage]$ ansible web  --list-hosts
          hosts (2):
            servera.lab.example.com
            serverb.lab.example.com
        [student@workstation deploy-manage]$ ansible all  --list-hosts
          hosts (3):
            localhost
            servera.lab.example.com
            serverb.lab.example.com
在ansible.cfg文件中添加[privilege_escalation] 部分,将ansible配置为受管主机上运行任务是自动使用 sudo 命令从student 切换到 root . ansible还应配置为提示您输入 student用户用于sudo命令的密码
        [student@workstation deploy-manage]$ vim ansible.cfg
        添加:
        [privilege_escalation]
        become = true
        become_method = sudo
        become_user = root
        become_ask_pass = true

再次运行ansible --list-hosts命令,以验证现在是否提示您输入sudo 密码。提示输入sudo密码时,请输入student,即使它不用于本次空运行
        [student@workstation deploy-manage]$ ansible intranetweb  --list-hosts
        BECOME password: 
          hosts (1):
            servera.lab.example.com

完成:
    清理本练习

        [student@workstation deploy-manage]$ lab deploy-manage finish

        Finishing lab exercise work:

         · Cleaning workstation:.......................................  SUCCESS

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值