1. Ansible is configured on Jump server with oracle so using inbuilt ansible ssh plugin, I am logging to below mention servers in my hosts file using Oracle
  2. Once successful login I am creating /tmp/cleanup_zfs directory to run shell scripts
  3. Shell script identifies /zfss* file systems and calculates used percentage! If used percentage is greater than Threshold value in the script.

Ansible modules

host.ini
[local]
localhost ansible_connection=local
[test]
dbadeeds ansible_host=10.0.0.8 ansible_port=22 ansible_user=oracle

zfs_cleanup.yml
---
  - name: Perform Oracle ZFS Cleanup
    hosts: zfs
    serial: 1
    roles:
      #-
      - oracle-zfs
    vars:
      action: zfs


oracle-zfs]$ ls -ltr
total 0
drwxr-xr-x 2 oracle oinstall 21 Sep  3  2021 defaults
drwxr-xr-x 2 oracle oinstall 21 Sep  3  2021 handlers
drwxr-xr-x 2 oracle oinstall 37 Sep  3  2021 tests
drwxr-xr-x 2 oracle oinstall 40 Sep  3  2021 vars
drwxr-xr-x 2 oracle oinstall 83 Oct 19  2021 files
drwxr-xr-x 2 oracle oinstall 27 Oct 20  2021 templates
drwxr-xr-x 2 oracle oinstall 88 Oct 20  2021 tasks

 defaults]$ cat main.yml
---
# defaults file for ansible-oracle-change-pwd

orclchangepwd:
    #
    # This installer is capable of three different installation
    # methods:
    #
    #   pkg:                Fetch the pkg yml file which helps to install on non cdb databases
    #   pdb:                Fetch the pdb yml file change database passwords on pdb databases
    #   dbsnmp:             Fetch the dbsnmp yml file & run from OEM server using Emcli
    #   dbauto:             Fetch the dbauto yml file for all oracle databases activities
    #
    #
    install_method: "{{ action }}"

    #
    #
    retries: 3

    # If using 'api' or 'url' methods, how many seconds should the
    # installer wait between retries?
    delay: 3

    install_temp_dir: ""

    remove_agent_id: false


cat ../tasks/main.yml
- name: Oracle Database Automation Installer | Validate Required Parameters and Environment
  assert:
    that:
        # - crowdstrike.api_url is defined
        # - crowdstrike.api_client_id is defined
        # - crowdstrike.api_client_secret is defined
        - ansible_pkg_mgr is defined
        - ansible_pkg_mgr in ['yum', 'pdb', 'pkg', 'dbauto', 'dbsnmp', 'zfs']

- name: Oracle Database Automation | Beginning the DBA activity
  include_tasks: dbauto.yml
  when: orclchangepwd.install_method == "dbauto"

- name: Oracle Database Automation | Beginning the DBA activity
  include_tasks: zfs.yml
  when: orclchangepwd.install_method == "zfs"

- name: Oracle Change Password Installer | Beginning for DBSNMP user from OEM
  include_tasks: dbsnmp.yml
  when: orclchangepwd.install_method == "dbsnmp"
  


cat /tasks/zfs.yml

- name: create ansible stage directory Oracle ZFS Mounts
  file:
      path: "/tmp/{{ stage_ansible }}"
      state: directory
  register: cdirout
- name: change to working directory
  shell: "cd /tmp/{{ stage_ansible }}"

- name: Copy Oracle ZFS Cleanup Script template file to remote server
  template: src=templates/cleanup_zfs.j2 dest=/tmp/{{ stage_ansible }}/cleanup_zfs.sh mode=755
  register: fileout

- name: Check the file
  shell: ls "/tmp/{{ stage_ansible }}/cleanup_zfs.sh"

- name: set env path shell script
  shell: sed -i -e 's/\r$//' "/tmp/{{ stage_ansible }}/cleanup_zfs.sh"

- name: Run ZFS Check & Cleanup shell script
  command: sh "/tmp/{{ stage_ansible }}/cleanup_zfs.sh"
  become_user: oracle
  register: script_output

- debug:
    var: script_output.stdout_lines

 vars]$ cat main.yml
---
# vars file for change_pwd-role
pdb_working_folder: /u01/app/oracle/ansible/pdb
stage_ansible: zfs_cleanup

Execution: time ansible-playbook -i host.ini zfs_cleanup.yml

time ansible-playbook -i host.ini zfs_cleanup.yml

oradb-automation-master]$ time ansible-playbook -i host.ini zfs_cleanup.yml
[WARNING]: Found variable using reserved name: action


PLAY [Perform Oracle ZFS Cleanup] ************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************
ok: [deeedsdpp001t0x]


TASK [oracle-zfs : create ansible stage directory Oracle ZFS Mounts] *************************************************************************************************************

changed: [deeedsoemora901t1x]
ok: [deeedsdpp002t0x]


TASK [oracle-zfs : change to working directory] **********************************************************************************************************************************
changed: [deeedsoemora901t1x]


TASK [oracle-zfs : Copy Oracle ZFS Cleanup Script template file to remote server] ************************************************************************************************
changed: [deeedsoemora901t1x]


TASK [oracle-zfs : Check the file] ***********************************************************************************************************************************************
changed: [deeedsoemora901t1x]
c

TASK [oracle-zfs : set env path shell script] ************************************************************************************************************************************
[WARNING]: Consider using template or lineinfile module rather than running sed

changed: [deeedsoemora901t1x]

TASK [oracle-zfs : Run ZFS Check & Cleanup shell script] *************************************************************************************************************************
changed: [deeedsoemora901t1x]


TASK [oracle-zfs : debug] ********************************************************************************************************************************************************
ok: [deeedsdpp001t0x] => {
"script_output.stdout_lines": []
}
ok: [deeedsdpp002t0x] => {
"script_output.stdout_lines": [
"",
" The filesystem /zfssb/dpa_ora_bkup2 is (86%) used on Server deeedsdpp002t0x as of Wed Oct 20 12:18:57 PDT 2021",
"",
"",
" ZFS Filesystem",
"deeedszfsnas922t1a-data:/export/dpa2-prod-backups/bkup2 "
]
}



PLAY RECAP ***********************************************************************************************************************************************************************
deeedsdpp001t0x : ok=10 changed=5 unreachable=0 failed=0



real 0m25.676s
user 0m8.440s
sys 0m4.812s

Leave a comment