2024年7月4日 星期四

【IT Notes】RHCE測驗第八題 USE ROLES FROM ANSIBLE GALAXY

 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.


【題前說明】

這題落落長寫了一大堆看似很嚇人,卻是解題過程最短的,乍看之下以為要做什麼大工程,其實就只是把第六題下載並安裝好的兩個roles分別套用到兩個群組上:balancer套用在balancers群組上;phpinfo套用在webservers群組,用的指令是ansible-galaxy,最後還要自己驗證一下結果。
一.解題過程:

[student@workstation ansible]$ vim roles.yml
---
- name: gather facts
  hosts: webservers

- name: config balancer
  hosts: balancers
  roles:
    - balancer

- name: config phpinfo
  hosts: webservers
  roles:
    - phpinfo


二.驗證結果

[student@workstation ansible]$ ansible-playbook -C roles.yml \\試跑看看是否正常


[student@workstation ansible]$ ansible-playbook roles.yml \\沒問題就正式

驗證balancer的付載平衡功能是否正常,用curl指令來檢查node5,每次戳它都會自動切換就表示成功了。

[student@workstation ansible]$ curl node5
Welcome to node3 on 172.25.250.12

[student@workstation ansible]$ curl node5
Welcome to node4 on 172.25.250.13

用瀏覽器打開node3和node4,看看是否有把訊息秀出來就知道是否成功。



三.恢復解題前的環境

恢復解題前的方式就是用ansible-galaxy,把剛剛裝過的roles都卸載即可。
[student@workstation ansible]$ vim 08-lab-galaxy-role-stop.yml
---
- 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


[student@workstation ansible]$ ansible-playbook 08-lab-galaxy-role-stop.yml


沒有留言:

張貼留言

【當兵回憶】八里連

 在我心目中新兵日記是天花板等級的軍教片,並不是說沒有比它更好的作品,只是因為它的在拍攝的背景和時間,也正是我在服兵役的同時,老婆很多次好奇問我,為什麼我總是放在YouTube的新兵日記直播,我都說我只放在有個聲音在,我沒有真正在看,但這行為仔細想想也好多年了吧!台詞聽到我都會背...