开放式研究实验:实施playbook

首先登录workstation.
        [kiosk@foundation0 ~]$ ssh student@workstation
        Warning: Permanently added 'workstation,172.25.250.9' (ECDSA) to the list of known hosts.
        Activate the web console with: systemctl enable --now cockpit.socket
在workstation 上,运行 lab playbook-review start 命令。此功能将确保受管主机serverb.lab.example.com 可在网络上访问。它也将确保控制节点上安装正确的ansible 配置文件和清单文件。
        [student@workstation ~]$ lab playbook-review start 

        Starting the lab on :

         · Verifying Ansible installation..............................  SUCCESS
        · Creating working directory.................................. SUCCESS
         · Deploying Ansible inventory.................................  SUCCESS
         · Deploying ansible.cfg.......................................  SUCCESS

workstation 上已经为ansible 项目创建了工作目录 /home/student/playbook-review 。该目录已填充了ansible.cfg 配置文件和inventory 文件。此清单文件中已经定义了受管主机 serverb.lab.example.com
1、新建一个playbook /home/student/playbook-review/internet.yml,再添加所需要的条目,一开始名为Enable internet services 的第一个play ,并指定它适用的受管主机 serverb.lab.exmple.com. 添加一个条目来启用特权升级,再添加一个条目来启动任务列表。
[student@workstation playbook-review]$ vim internet.yml   
添加:
---
- name: Enable internet services
  hosts: serverb.lab.example.com
  become: yes
  tasks:
    - name: latest version of all required packages installed
      yum:
        name:
          - firewalld
          - httpd
          - mariadb-server
          - php
          - php-mysqlnd
        state: latest

    - name: firewalld enabled and running
      service:
        name: firewalld
        enabled: true
        state: started

    - name: firewalld permits http service
      firewalld:
        service: http
        permanent: true
        state: enabled
        immediate: yes

    - name: httpd enabled and running
      service:
        name: httpd
        enabled: true
        state: started

    - name: mariadb enabled and running
      service:
        name: mariadb
        enabled: true
        state: started

    - name: test php page is installed
      get_url:
              url: "http://materials.example.com/labs/playbook-review/index.php"
              dest: /var/www/html/index.php
              mode: 0644

- name: Test internet web server
  hosts: localhost
  become: no
  tasks:
    - name: connect to internet web server
      uri:
        url: http://serverb.lab.example.com
        status_code: 200
2、验证internet.yml playbook的语法。
        [student@workstati on playbook-review]$ ansible-playbook --syntax-check internet.yml

        playbook: internet.yml

3、使用ansible-playbook命令运行playbook.
        [student@workstation playbook-review]$ ansible-playbook internet.yml

        PLAY [Enable internet services]         **************************************************************************************************

        TASK [Gathering Facts]         ***********************************************************************************************************
        ok: [serverb.lab.example.com]

        TASK [latest version of all required packages installed]         *************************************************************************
        ok: [serverb.lab.example.com]

        TASK [firewalld enabled and running]         *********************************************************************************************
        ok: [serverb.lab.example.com]

        TASK [firewalld permits http service]         ********************************************************************************************
        changed: [serverb.lab.example.com]

        TASK [httpd enabled and running]         *************************************************************************************************
changed: [serverb.lab.example.com]

        TASK [mariadb enabled and running]         ***********************************************************************************************
        changed: [serverb.lab.example.com]

        TASK [test php page is installed]         ************************************************************************************************
        changed: [serverb.lab.example.com]

        PLAY [Test internet web server]         **************************************************************************************************

        TASK [Gathering Facts]         ***********************************************************************************************************
        ok: [localhost]

        TASK [connect to internet web server]         ********************************************************************************************
        ok: [localhost]

        PLAY RECAP         ***********************************************************************************************************************
        localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
        serverb.lab.example.com    : ok=7    changed=4    unreachable=0    failed=0    skipped=0            rescued=0    ignored=0   

        [student@workstation playbook-review]$ cd
        [student@workstation ~]$ lab playbook-review grade

        Grading the student's work on serverb:

         · Verify httpd package installation...........................  PASS
         · Verify firewalld package installation.......................  PASS
         · Verify mariadb-server package installation..................  PASS
         · Verify php package installation.............................  PASS
         · Verify php-mysqlnd package installation.....................  PASS
         · Verify httpd service........................................  PASS
         · Verify firewalld service.................................... PASS
         · Verify mariadb service......................................  PASS
         · Verify firewalld configuration..............................  PASS
         · Verify web site.............................................  PASS
        Overall lab grade...............................................  PASS

完成
        在workstation上,运行 lab deploy-review finish 脚本俩清理本实验中创建的资源.
        [student@workstation ~]$ lab playbook-review finish

        Cleaning up the lab on serverb:

        Cleanup
         · Remove firewall configuration...............................  SUCCESS
         · Remove web content..........................................  SUCCESS
         · Remove httpd package........................................  SUCCESS
         · Remove mariabdb-server package..............................  SUCCESS
         · Remove php package..........................................  SUCCESS
         · Remove php-mysqlnd package.................................. SUCCESS

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值