Create a playbook called /home/student/ansible/roles.yml with the following requirements:
The playbook contains a play that runs on hosts in the balancers host group and uses the balancer role.
- This role configures a service to load balance web server requests between hosts in the webservers host group.
- Browsing to hosts in the balancers host group (for example http://node5.example.com/) produces the following output:
Welcome to node3.example.com on 172.25.250.12
- Reloading the browser produces output from the alternate web server:
Welcome to node4.example.com on 172.
25.250.13
The playbook contains a play that runs on hosts in the webservers host group and uses the phpinfo role.
Browsing to hosts in the webservers host group with the URL /hello.php produces the following output:
Hello PHP World from FQDN
where FQDN is the fully qualified domain name of the host.
For example, browsing to http://node3.example.com/hello.php, produces the following output:
Hello PHP World from node3.example.com
along with various details of the PHP configuration including the version of PHP that is installed.
Similarly, browsing to http://node4.example.com/hello.php, produces the following output:
Hello PHP World from node4.example.com
along with various details of the PHP configuration including the version of PHP that is installed.
---
- name: gather facts
hosts: webservers
- name: config balancer
hosts: balancers
roles:
- balancer
- name: config phpinfo
hosts: webservers
roles:
- phpinfo
驗證balancer的付載平衡功能是否正常,用curl指令來檢查node5,每次戳它都會自動切換就表示成功了。
三.恢復解題前的環境
---
- name: gater facts
hosts: webservers, balancers
- name: remove role balancer
hosts: balancers
tasks:
- name: remove role balancer
shell: ansible-galaxy remove balancer
- name: remove role phpinfo
hosts: webservers
tasks:
- name: remove role phpinfo
shell: ansible-galaxy remove phpinfo
沒有留言:
張貼留言