Ansible-7-playbook综合实验
//开始练习
[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
[student@workstation ~]$ cd playbook-review/
[student@workstation playbook-review]$ ls
ansible.cfg inventory
[student@workstation playbook-review]$ cat ansible.cfg
[defaults]
inventory=inventory
remote_user=devops
[privilege_escalation]
become=False
become_method=sudo
become_user=root
become_ask_pass=False
[student@workstation playbook-review]$ cat inventory
serverb.lab.example.com
[student@workstation playbook-review]$ ls
ansible.cfg internet.yml inventory
[student@workstation playbook-review]$ cat internet.yml
---
- name: Enable internet services
hosts: serverb.lab.example.com
become: yes
tasks:
- name: Install the latest versions of firewall, mariadb-server, php, and php-mysqlnd package
yum:
name:
- httpd
- firewalld
- mariadb-server
- php
- php-mysqlnd
state: latest
- name: firewalld enabled and running
service:
name: firewalld
state: started
enabled: true
- name: firewalld access is allowed to the httpd service
firewalld:
service: http
permanent: true
state: enabled
immediate: yes
- name: httpd enabled and running
service:
name: httpd
state: started
enabled: true
- name: mariadb enabled and running
service:
name: mariadb
state: started
enabled: true
- name: get_url get index html file
get_url:
url: http://materials.example.com/labs/playbook-review/index.php
dest: /var/www/html
- name: connection test
hosts: localhost
become: no
tasks:
- name: connection to internet web server
uri:
url: http://serverb.lab.example.com
return_content: yes
status_code: 200
[student@workstation playbook-review]$ ansible-playbook internet.yml
PLAY [Enable internet services] ***********************************************************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************************************************************************
ok: [serverb.lab.example.com]
TASK [Install the latest versions of firewall, mariadb-server, php, and php-mysqlnd package] **********************************************************************************************************************************
ok: [serverb.lab.example.com]
TASK [firewalld enabled and running] ******************************************************************************************************************************************************************************************
ok: [serverb.lab.example.com]
TASK [firewalld access is allowed to the httpd service] ***********************************************************************************************************************************************************************
ok: [serverb.lab.example.com]
TASK [httpd enabled and running] **********************************************************************************************************************************************************************************************
ok: [serverb.lab.example.com]
TASK [mariadb enabled and running] ********************************************************************************************************************************************************************************************
changed: [serverb.lab.example.com]
TASK [get_url get index html file] ********************************************************************************************************************************************************************************************
changed: [serverb.lab.example.com]
PLAY [connection test] ********************************************************************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [connection 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=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[student@workstation playbook-review]$ 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