2024年4月3日 星期三

【IT Notes】RHCE測驗第四題 INSTALL PACKAGES

Create a playbook called /home/student/ansible/packages.yml that:

  • Installs the php and mariadb packages on hosts in the devtest, and prod host groups

  • Installs the RPM Development Tools package group on hosts in the dev host group

  • Updates all packages to the latest version on hosts in the dev host group

【題前說明】
 這是很入門的考題,目的只是要安裝php和mariadb在node1、node2、node3和node4上;然後node1上再多裝dev tools,並且更新每一台node上的套件至最新版本,全部動作都用ansible來部署。

一.解題過程:

1.建立package.yml,並直接編輯

[student@workstation ansible]$ touch packages.yml
[student@workstation ansible]$ vim packages.yml 
---
  hosts: dev,test,prod
  tasks:
    - name: install php and mariadb
      dnf:
        name: "{{ item }}"
        state: present
      loop:
        - php
        - mariadb
    - name: install devtools on host dev
      dnf:
        name: rpmdevtools       
        state: present
      when: ansible_hostname in groups.dev
    - name: upgrade all packages on host dev
      dnf:
        name: '*'
        state: latest
      when: ansible_hostname in groups.dev
- name: install packages
\\考題這裡要下載的是'@RPM Development Tools',不過我沒有這包套件,就改成官方的rpmdevtools,應該也是類似的東西

二.驗證結果

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



[student@workstation ansible]$ ansible-playbook packages.yml   \\沒問題就正式
[student@workstation ansible]$ ansible dev -m shell -a 'rpm -qa | grep mariadb'
[student@workstation ansible]$ ansible dev -m shell -a 'rpm -qa  | grep php'
\\驗證dev節點是否有安裝完畢

回傳訊息是這樣就表示安裝成功

三.恢復解題前的環境

回復變更前環境,把剛剛所有安裝的軟體都移除,也順便把本機上的package.yml也刪掉。

[student@workstation ansible]$ vim 04-lab-collection-stop.yml

---
- name: remove packages
  hosts: dev,test,prod
  tasks:
    - name: remove php mariadb
      yum:
        name: "{{ item }}"
        state: absent
      loop:
      - php
      - mariadb
    - name: remove packages groups
      yum:
        name: "rpmdevtools"
        state: absent
      when: inventory_hostname in groups.dev

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


[student@workstation ansible]$ ansible-playbook 04-lab-collection-stop.yml

沒有留言:

張貼留言

【IT Notes】透過api移轉Gmail到Exchange

 在雲端裡面串接api不是一件很好學的技術,第一次有機會學習到將GWS的Gmail信件全部轉移到M365的Exchange,其實方法很多種,像以前用的pst檔匯出轉移的方式等,但透過api串接,可以批次和排程轉移,是非常方便且準確的作法。唯一讓人感到困難的是學習成本不小,通常需要...