1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

ansible で OracleDB にRU適用してみましたのでまとめます。
簡単ですがイメージは下記の通り。
qiita-ansible-img.png

ansible と cx_Oracle の導入自体は下記を参考にさせていただきました:bow:

また、ansibleモジュールは下記の GitHubリポジトリを使わせていただきました:bow:

必要なファイルの準備

まずはインベントリファイルですが、ローカルなのでシンプルです。

inventory.ini
[ansible_target]
localhost

[ansible_target:vars]
ansible_user=oracle
ansible_password=

次に playbook です。
インスタンスの起動と PDBの起動は先述の GitHubリポジトリ上で適当なものを見つけられなかったので、oracle_sqldba を使用しました。(探し方が悪いだけかも)

apply_ru.yaml
- hosts: ansible_target
  gather_facts: false

  tasks:
    - name: opatch apply
      oracle_opatch:
         oracle_home: /opt/oracle/product/19c/dbhome_1
         patch_base: /media/dbfun_20250212_ru_a2z/37260974
         stop_processes: True
         
    - name: startup
      oracle_sqldba:
         sql: startup
         oracle_home: /opt/oracle/product/19c/dbhome_1
         oracle_db_name: ORCLCDB1

    - name: pdb open
      oracle_sqldba:
         sql: alter pluggable database orclpdb11 open
         oracle_home: /opt/oracle/product/19c/dbhome_1
         oracle_db_name: ORCLCDB1

    - name: datapatch
      oracle_datapatch:
         oracle_home: /opt/oracle/product/19c/dbhome_1
         db_name: ORCLCDB1
         password: password

ディレクトリ構成は下記の通り。
(unzipしたRUを配置したディレクトリは opatch_apply の patch_base に指定)

ディレクトリ構成
[oracle@cac1716e92f6 ansible-test]$ tree
.
├── apply_ru.yaml
├── inventory.ini
└── library
    ├── oracle_datapatch.py
    ├── oracle_opatch.py
    └── oracle_sqldba.py

いざ実行!

…の前に状態確認です。

確認#1
SQL> select version_full from product_component_version;

VERSION_FULL
-------------
19.3.0.0.0
確認#2
SQL> select status, description from dba_registry_sqlpatch;

STATUS
-------------------------
DESCRIPTION
-----------------------------------------------------
SUCCESS
Database Release Update : 19.3.0.0.190416 (29517242)

19.3で間違いないことを確認して実行!

playbook実行
[oracle@cac1716e92f6 ansible-test]$ ansible-playbook -i inventory.ini --connection=local apply_ru.yaml

PLAY [ansible_target] **********************************************************

TASK [opatch apply] ************************************************************
changed: [localhost]

TASK [startup] *****************************************************************
changed: [localhost]

TASK [pdb open] ****************************************************************
changed: [localhost]

TASK [datapatch] ***************************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

[oracle@cac1716e92f6 ansible-test]$

無事完了したので、改めて状態確認です。

確認#1
SQL> select version_full from product_component_version;

VERSION_FULL
------------
19.26.0.0.0
確認#2
SQL> select status, description from dba_registry_sqlpatch;

STATUS
-------------------------
DESCRIPTION
-----------------------------------------------------
SUCCESS
Database Release Update : 19.3.0.0.190416 (29517242)

SUCCESS
Database Release Update : 19.26.0.0.250121 (37260974)

19.26になっていることを確認できました!

次にansibleで試そうと思ってること

  • 個別パッチ (Interim patch) が適用されてるDBに対するRU適用
  • RAC環境へのRU適用
  • ansibleとオラクルDBを別コンテナにする
  • PostgreSQL も ansible でメンテナンス
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?