Reputation: 97
I am trying to automate the installation of an Oracle RPatch file on a node computer with Ansible. The problem here is that I need to keep passing the patch ID, through Ansible, manually. Is there any way to pass that patch id as a parameter? Thanks for your time. Here is the sample of the code I am writing, so that you identify better what I am trying to substitute.
---
- hosts: web #group of hosts on host file
remote_user: client
become: yes #become super SU
tasks:
- name: Test Host Connection
ping:
- name: Copy Opatch zipfile to the Target Oracle_home
copy:
src: #substitute for the oracle orpatch file
dest: /tmp
- name: Upgrade Rpatch
shell: unzip -o /tmp/p6880880_112000_Linux-x86-64.zip -d $ORACLE_HOME #default is /u01/oracle/11204
register: unzip
- name: Define Retail Home Path
shell: export RETAIL_HOME = </u01/app/rms>
- name: Move to Retail_Home Directory
shell: cd $RETAIL_HOME
- name: execute rpatch to analyse the Patch
shell: orpatch analyze -s /tmp/patch_id #define here the patch__id
- name: ORPatch Apply
shell: orpatch apply
- name: List the Inventory
shell: orpatch lsinventory
Upvotes: 0
Views: 715
Reputation: 28493
What you are looking for are playbook variables. I would suggest reading https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html as it will familiarize yourself with different ways of using variables. But I will show one way to pass it on the command line.
The following example makes your patch_id a templated variable. It also runs it through the mandatory
filter making it required (playbook will fail early if it is not set).
---
- hosts: web #group of hosts on host file
remote_user: client
become: yes #become super SU
tasks:
- name: Test Host Connection
ping:
- name: Copy Opatch zipfile to the Target Oracle_home
copy:
src: #substitute for the oracle orpatch file
dest: /tmp
- name: Upgrade Rpatch
shell: unzip -o /tmp/p6880880_112000_Linux-x86-64.zip -d $ORACLE_HOME #default is /u01/oracle/11204
register: unzip
- name: Define Retail Home Path
shell: export RETAIL_HOME = </u01/app/rms>
- name: Move to Retail_Home Directory
shell: cd $RETAIL_HOME
- name: execute rpatch to analyse the Patch
shell: orpatch analyze -s /tmp/{{ patch_id | mandatory }}
- name: ORPatch Apply
shell: orpatch apply
- name: List the Inventory
shell: orpatch lsinventory
You would then set patch_id
at runtime using -e
like:
ansible-playbook -i myinventory -e patch_id=mypatchid myplaybook.yaml
Hope this helps!
Upvotes: 1