2024年3月27日 星期三

【IT Notes】RHCE測驗第二題 CREATE YUM REPOSITORIES

As a system administrator, you will need to install software on the managed nodes. Create the playbook /home/student/ansible/yum_repo.yml which creates the following yum repositories on each of the managed nodes as follows:

【題前說明】
 這題在RHCE8不是用yml來做的,而是用shell的方式安裝yum repo,到了RHCE9以後就變成要求要用ansible執行yml來部署,這題要是做不出來的話,當然後面的很多題目可能也就沒有檔案可以下載,最後考試
也泡湯了。如同下面的第三題,這兩題讓我印象深刻,因為我是上RHCE8,但考前上了衝刺班得到了改版後改提也變更的資訊,一個禮拜之內趕緊補強這幾題,幸虧最後來得及複習,但考是坐我旁邊的同學就沒那麼幸運,記得當時他很慌張,因為他也跟我一樣是上一版本的課程,不過他沒有上衝刺班,等於第二和第三題他都不曉得,所以得要強調這幾題目前的變化!


一.解題過程:

1.建立yum_repo.yml檔

[student@workstation ansible]$ touch yum_repo.yml   
[student@workstation ansible]$ vim yum_repo.yml      
---
- name: create yum repos
  hosts: all
  tasks:
    - name: import rpm key
      rpm_key:
        key: http://example.classroom.com/repos/RPM-GPG-KEY-Rocky-9
        state: present
    - name: create BaseOS repo
      yum_repository:
        name: EX294_BASE
        description: EX294 base software
        baseurl: http://example.classroom.com/repos/baseos
        enabled: yes
        gpgcheck: yes
    - name: create AppStream repo
      yum_repository:
        name: EX294_STREAM
        description: EX294 stream software
        baseurl: http://example.classroom.com/repos/appstream
        enabled: yes
        gpgcheck: yes


2.使用ansible-play -C yum_repo.yml或者是ansible-play --syntax yum_repo.yml,驗證一下yml檔有沒有問題

回傳每一台node都是綠色的回應就代表可以布署了

[student@workstation ansible]$ ansible all -m shell -a 'yum repolist'  \\驗證部署結果
以上回應的畫面就可以顯示每台node的repo都建立完畢


二.恢復解題前的環境

一樣如果要反覆做題目的話,需要做一個yml來恢復變更前的環境。

[student@workstation ansible]$ vim 02-lab-yumrepo-stop.yml

---
- name: remove all repo
  hosts: all
  tasks:
    - name: remove base repo
      shell: sudo rm -f /etc/yum.repos.d/EX294_BASE.repo

    - name: remove centosplus repo
      shell: sudo rm -f /etc/yum.repos.d/EX294_STREAM.repo

- name: remove repo.yml
  hosts: 127.0.0.1
  tasks:
    - name: remove repo.yml
      file:
        path: /home/student/ansible/yum_repo.yml
        state: absent


[student@workstation ansible]$ ansbile-playbook 02-lab-yumrepo-stop.yml



沒有留言:

張貼留言

【當兵回憶】八里連

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