已归录

练习环境(可忽略)

$ lab playbook-review start
$ lab playbook-review grade
$ lab playbook-review finish

剧本要求

  1. Create a new playbook, /home/student/playbook-review/internet.yml and add the necessary entries to start a first play named Enable internet services and specify its intended managed host, serverb.lab.example.com. Add an entry to enable privilege escalation, and one to start a task list.
  2. Add the required entries to the /home/student/playbook-review/internet.yml file to define a task that installs the latest versions of firewalld, httpd, mariadb-server, php, and php-mysglnd packages.
  3. Add the necessary entries to the /home/student/playbook-review/internet.yml file to define the firewall configuration tasks. They should ensure that the firewalld service is enabled and running, and that access is allowed to the httpd service.
  4. Add the necessary tasks to ensure the httpd and mariadb services are enabled and running.
  5. Add the necessary entries to define the final task for generating web content for testing. Use the get_url module to copy http://materials.example.com/labs/playbook-review/index.php to /var/www/htm1/ on the managed host.
  6. In /home/student/playbook-review/internet.yml, define another play for the task to be performed on the control node. This play will test access to the web server that should be running on the serverb managed host. This play does not require privilege escalation, and will run on the localhost managed host.
  7. Add a task that tests the web service running on serverb from the control node using the uri madule. Check for a return status code of 200.
  8. Verify the syntax of the internet.yml playbook.
  9. Use the ansible-playbook command to run the playbook. Read through the output generated to ensure that all tasks completed successfully.

剧本内容

---
- 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 the internet web server
      uri:
        url: http://serverb.lab.example.com
        status_code: 200

运行剧本

# ansible-playbook [--syntax-check] internet.yml
-- By 许望(RHCA、OCM、VCP)
最后修改:2020 年 05 月 22 日 01 : 17 PM
如果觉得我的文章对你有用,请随意赞赏